Classpath scanning does not work in tests using the module path [SPR-16977]
See original GitHub issueAndy Wilkinson opened SPR-16977 and commented
It appears the classpath scanning doesn’t work when Surefire launches the JVM configured to use the module path. target/classes
is placed on the module path and target/test-classes
is patched into this module but classpath scanning only finds classes in target/test-classes
.
I have attached a minimal sample that should reproduce the problem when built (mvn test
) with Java 10. The sysout from the test should show that only the test class has been found:
[INFO] Running com.example.ScanningTest
[file [/Users/awilkinson/dev/temp/module-path-scanning/target/test-classes/com/example/ScanningTest.class]]
To my rather untrained eye, building with -X
and examining the arguments that Surefire uses to launch the forked JVM (in target/surefire
) suggests that Surefire’s configuration of the JVM is correct.
When the sample is modified to work with Java 8 (remove module-info.java
and change the compiler plugin configuration to remove <release>10</release>
) the class in target/classes
is also found:
[INFO] Running com.example.ScanningTest
[file [/Users/awilkinson/dev/temp/module-path-scanning/target/test-classes/com/example/ScanningTest.class], file [/Users/awilkinson/dev/temp/module-path-scanning/target/classes/com/example/One.class]]
Affects: 5.0.7
Reference URL: https://github.com/spring-projects/spring-boot/issues/13581
Attachments:
- module-path-scanning.zip (3.66 kB)
Issue Links:
- #20937 Compatibility with JDK 11
2 votes, 7 watchers
Issue Analytics
- State:
- Created 5 years ago
- Comments:26 (4 by maintainers)
I had the same (or very similar) issue running tests with maven-failsafe-plugin 3.0.0-M5 on AdoptOpen JDK 11. The work around is to disable using module path in plugin’s configuration
<useModulePath>false</useModulePath>
Another year has passed. To me this still is a showstopper.