We use assemble task in our CI/CD pipeline to build artifacts. From Spring Boot 2.5.0 jar task generates an additional jar archive which ends with -plain.jar. This breaks builds if you use patterns like *.jar to copy the build archive. To restrict the additional jar creation Spring Boot documentation provides guidance here that we can disable the jar task if we prefer that the plain archive isn’t built at all. This doesn’t play well with nativeCompile task.
To Reproduce Environment - Spring Boot: 3.0.0-RC2 - Native Buildtools: 0.9.17 - GraalVM version : graalvm-ce-java17-22.3.0 - JDK version: openjdk 17.0.5 - Architecture: AMD64
Sample project https://github.com/michalkrajcovic/spring-native-plain-archives
Compile
./gradlew nativeCompile
Fails with
Error: Main entry point class 'com.example.springnativeplainarchives.Application' neither found on the classpath nor on the modulepath.
Comment From: wilkinsona
Thanks for trying the release candidate.
The behavior you are seeing is to be expected as nativeCompile uses the jar task as an input. This is done by adding a dependency on the project itself to the nativeImageCompileOnly configuration. When the jar task is disabled, the classpath for nativeCompile is incomplete as none of the project's own classes can be found.
We'll update the documentation to indicate that you should not disable the jar task if you want to build a native image.
As an alternative, if you need the jar task to remain disabled, add the main source set's output as a dependency of the nativeImageCompileOnly configuration:
dependencies {
nativeImageCompileOnly(sourceSets.main.output)
}