I'm trying to run my app as an executable jar using Spring Boot version 2.7.7 with devtools version 2.7.8 scoped in my gradle configuration as 'developmentOnly' scope. When I try to launch the build jar using "java -jar MyApplication.jar", I get the following error:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
        at com.application.something.MyApplication.main(MyApplication.java:22)
        ... 8 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:476)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 9 more

Note that I have removed the devtools dependency and try to run my built jar artifact as noted above and everything works as expected. I thought that this issue was solved in a previous release of SpringBoot (2.3.X?) from looking at the issues log. Looking for some guidance on this.

Comment From: wilkinsona

We're not aware of any problems with developmentOnly and I cannot reproduce the problem you have described with the following build.gradle:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.8'
    id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: mikesmithson

yes, SpringBoot version 2.7.8 with devtools version 2.7.8 works but we are not using that version of SpringBoot as of yet. We have some other issues we have to fix in our application to upgrade.

Comment From: wilkinsona

I can't reproduce the problem with 2.7.7, or by mixing 2.7.7 and 2.7.8 (which is unsupported anyway).

Given that it works for you with 2.7.8 there's nothing that we can do here. Whatever the problem may have been has apparently already been fixed.