2

I have a Spring Boot application which fails to start in IntelliJ 2017.1.5, as soon as I add the Spring Boot developer tools to the Gradle build like this:

dependencies {
  compile("org.springframework.boot:spring-boot-starter-web")
  compile("org.apache.httpcomponents:httpclient:4.5.3")
  compile("com.fasterxml.jackson.core:jackson-databind:2.8.8.1")
  compile("commons-validator:commons-validator:1.6")

  // This line breaks IntelliJ compatibility:
  optional("org.springframework.boot:spring-boot-devtools")

  optional("org.springframework.boot:spring-boot-configuration-processor")
  testCompile("org.springframework.boot:spring-boot-starter-test")
  testCompile("junit:junit:4.12")
}

Without the spring-boot-devtools everything is fine, as soon as I add them, starting the application (after refreshing the Gradle project in IntelliJ) fails with a NoClassDefFoundError:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/web/client/RestTemplateBuilder
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.web.client.RestTemplateBuilder
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

I'm pretty sure it's an IntelliJ issue, because the same application runs fine in Eclipse with the Spring Boot developer tools enabled.

Any ideas how to fix this?

anothernode
  • 5,100
  • 13
  • 43
  • 62
  • See http://stackoverflow.com/a/42588061/104891. – CrazyCoder Jul 10 '17 at 19:30
  • @CrazyCoder: Thanks, but I am using IntelliJ 2017.1.5... (should have included that in the original question). Also, it's only when I add the Spring Boot developer tools to the build. So I think it's a more specific problem than the one you linked to. – anothernode Jul 11 '17 at 10:24
  • Please check if https://youtrack.jetbrains.com/issue/IDEA-174993 is the case. – CrazyCoder Jul 11 '17 at 12:28
  • Yes, it looks like it is at least a very similar issue as IDEA-174993! When I go to `Project Structure / Modules / Dependencies`, I see that `spring-boot` and `spring-boot-autoconfigure` have scope `Provided`. When I then set the scope to `Compile`, the application starts fine. But after refreshing the Gradle project, the scope is back to `Provided`, just as described at IDEA-174993. Note also that another way to circumvent the problem for me, is to remove `spring-boot-devtools` from the build... – anothernode Jul 11 '17 at 16:33

1 Answers1

1

I was able to resolve this problem by changing the dependency to the spring-boot-devtools to:

runtime("org.springframework.boot:spring-boot-devtools")

Instead of

optional("org.springframework.boot:spring-boot-devtools")
anothernode
  • 5,100
  • 13
  • 43
  • 62