@sdeleuze pointed out that https://github.com/mhalbritter/spring-aot-jarsigner-reproducer fails with the following.
> Task :app:processTestAot FAILED
Error: Could not find or load main class org.springframework.test.context.aot.TestAotProcessor
Caused by: java.lang.ClassNotFoundException: org.springframework.test.context.aot.TestAotProcessor
The app project does not have a dependency on spring-test (or spring-boot-starter-test). So that explains why org.springframework.test.context.aot.TestAotProcessor cannot be found.
Comment From: snicoll
It could also impact the main goal if spring-boot isn't around as we need AotProcessor to invoke the engine.
Comment From: wilkinsona
I'm not yet sure if the current behaviour is a bad thing. If a user's applied Spring Boot's AOT plugin (either directly or by applying Boot's main plugin and the NBT plugin), I think that's a strong signal there they're building and testing a Boot app. In terms of changing the behaviour, we could:
- Skip the
processAotandprocessTestAottasks if the required dependencies are missing (I think this is technically possible) - Fail with a different error message
- Add the necessary dependencies implicitly
@sdeleuze and @sbrannen, what did you expect to happen in this situation?
Comment From: snicoll
I agree with Andy. I think it should fail but make it more obvious why that is. Checking that it does in a way that makes it obvious the project is misconfigured would be nice.
However, running mvn -Pnative on a multi-modules goal can be painful and skipping the modules automatically could be Maven idiomatic.
Comment From: sbrannen
The example project does not include any tests.
./gradlew build -x test succeeds.
./gradlew build fails with the aforementioned error.
./gradlew build -x processTestAot succeeds.
Thus, the issue is that processTestAot runs automatically even if there are no tests, and IMO that's what we should fix.
Attempting to build a project that does not include tests should not fail when trying to process non-existent tests for AOT.
The Native Build Tools project ran into similar issues where users complained about native tests failing when the project didn't contain any tests.
As Stéphane pointed out, this can be particularly cumbersome in multi-module projects (both for Gradle and Maven): some modules may contain tests while others do not.
Related Issues
- https://github.com/graalvm/native-build-tools/issues/81
- https://github.com/graalvm/native-build-tools/issues/188
Summary
I think processAot should probably fail with an informative message if the required dependencies are missing.
I think processTestAot should not run at all if there are no tests. If there are tests and required dependencies are missing, processTestAot should fail with an informative message.
Comment From: wilkinsona
Thanks, Sam. Skipping processAot when the main source set hasn't output anything and processTestAot when the test source set hasn't output anything sounds like a good idea to me.