Skip to content

Commit b12d8c4

Browse files
committed
Only configure whitebox test suite if the a test src folder exists
This is mainly for the default 'test' source set, which is always registered. If it is not used, the whitebox configuration will cause Gradle to think that there are supposed to be tests, because the main classes become part of the "test classes" set. This will cause Gradle to run the task without tests and throw an error (in recent Gradle versions).
1 parent ed6423f commit b12d8c4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/org/gradlex/javamodule/testing/JavaModuleTestingExtension.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ public JavaModuleTestingExtension(Project project, JavaModuleDetector moduleDete
6363
testing.getSuites().withType(JvmTestSuite.class).configureEach(jvmTestSuite -> {
6464
boolean isTestModule = jvmTestSuite.getSources().getJava().getSrcDirs().stream().anyMatch(src -> new File(src, "module-info.java").exists());
6565
if ("test".equals(jvmTestSuite.getName())) {
66-
jvmTestSuite.useJUnitJupiter(); // override old Gradle default to default to JUnit5 for all suites
66+
jvmTestSuite.useJUnitJupiter(); // override old Gradle convention to default to JUnit5 for all suites
6767
}
6868
if (isTestModule) {
6969
blackbox(jvmTestSuite);
7070
} else {
71-
whitebox(jvmTestSuite, conf -> conf.getOpensTo().add("org.junit.platform.commons"));
71+
boolean testFolderExists = jvmTestSuite.getSources().getJava().getSrcDirs().stream().anyMatch(File::exists);
72+
if (testFolderExists) {
73+
whitebox(jvmTestSuite, conf -> conf.getOpensTo().add("org.junit.platform.commons"));
74+
}
7275
}
7376
});
7477
}

0 commit comments

Comments
 (0)