@@ -63,20 +63,11 @@ public JavaModuleTestingExtension(Project project) {
6363 jvmTestSuite .useJUnitJupiter (); // override old Gradle convention to default to JUnit5 for all suites
6464 }
6565
66- boolean testFolderExists = jvmTestSuite .getSources ().getJava ().getSrcDirs ().stream ().anyMatch (File ::exists );
6766 if (isTestModule ) {
6867 blackbox (jvmTestSuite );
69- } else if ( testFolderExists ) {
68+ } else {
7069 whitebox (jvmTestSuite , conf -> conf .getOpensTo ().add ("org.junit.platform.commons" ));
7170 }
72-
73- // Remove the dependencies added by Gradle in case the test directory is missing. This allows the use of 'useJUnitJupiter("")' without hassle.
74- if (!testFolderExists ) {
75- project .getConfigurations ().getByName (jvmTestSuite .getSources ().getImplementationConfigurationName (), implementation ->
76- implementation .withDependencies (dependencySet -> dependencySet .removeIf (d -> "org.junit.jupiter" .equals (d .getGroup ()) && "junit-jupiter" .equals (d .getName ()))));
77- project .getConfigurations ().getByName (jvmTestSuite .getSources ().getRuntimeOnlyConfigurationName (), runtimeOnly ->
78- runtimeOnly .withDependencies (dependencySet -> dependencySet .removeIf (d -> "org.junit.platform" .equals (d .getGroup ()) && "junit-platform-launcher" .equals (d .getName ()))));
79- }
8071 });
8172 }
8273
@@ -124,6 +115,17 @@ public void whitebox(TestSuite jvmTestSuite) {
124115 */
125116 public void whitebox (TestSuite jvmTestSuite , Action <WhiteboxJvmTestSuite > conf ) {
126117 if (jvmTestSuite instanceof JvmTestSuite ) {
118+ SourceSet suiteSourceSet = ((JvmTestSuite ) jvmTestSuite ).getSources ();
119+ boolean testFolderExists = suiteSourceSet .getJava ().getSrcDirs ().stream ().anyMatch (File ::exists );
120+ if (!testFolderExists ) {
121+ // Remove the dependencies added by Gradle in case the test directory is missing. Then stop. This allows the use of 'useJUnitJupiter("")' without hassle.
122+ project .getConfigurations ().getByName (suiteSourceSet .getImplementationConfigurationName (), implementation ->
123+ implementation .withDependencies (dependencySet -> dependencySet .removeIf (d -> "org.junit.jupiter" .equals (d .getGroup ()) && "junit-jupiter" .equals (d .getName ()))));
124+ project .getConfigurations ().getByName (suiteSourceSet .getRuntimeOnlyConfigurationName (), runtimeOnly ->
125+ runtimeOnly .withDependencies (dependencySet -> dependencySet .removeIf (d -> "org.junit.platform" .equals (d .getGroup ()) && "junit-platform-launcher" .equals (d .getName ()))));
126+ return ;
127+ }
128+
127129 WhiteboxJvmTestSuite whiteboxJvmTestSuite = project .getObjects ().newInstance (WhiteboxJvmTestSuite .class );
128130 whiteboxJvmTestSuite .getSourcesUnderTest ().convention (project .getExtensions ().getByType (SourceSetContainer .class ).getByName (SourceSet .MAIN_SOURCE_SET_NAME ));
129131 whiteboxJvmTestSuite .getRequires ().addAll (requiresFromModuleInfo ((JvmTestSuite ) jvmTestSuite , whiteboxJvmTestSuite .getSourcesUnderTest (), false ));
0 commit comments