File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed
main/java/org/gradlex/javamodule/testing
test/groovy/org/gradlex/javamodule/testing/test Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -62,13 +62,20 @@ public JavaModuleTestingExtension(Project project) {
6262 if ("test" .equals (jvmTestSuite .getName ())) {
6363 jvmTestSuite .useJUnitJupiter (); // override old Gradle convention to default to JUnit5 for all suites
6464 }
65+
66+ boolean testFolderExists = jvmTestSuite .getSources ().getJava ().getSrcDirs ().stream ().anyMatch (File ::exists );
6567 if (isTestModule ) {
6668 blackbox (jvmTestSuite );
67- } else {
68- boolean testFolderExists = jvmTestSuite .getSources ().getJava ().getSrcDirs ().stream ().anyMatch (File ::exists );
69- if (testFolderExists ) {
70- whitebox (jvmTestSuite , conf -> conf .getOpensTo ().add ("org.junit.platform.commons" ));
71- }
69+ } else if (testFolderExists ) {
70+ whitebox (jvmTestSuite , conf -> conf .getOpensTo ().add ("org.junit.platform.commons" ));
71+ }
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 ()))));
7279 }
7380 });
7481 }
Original file line number Diff line number Diff line change @@ -101,4 +101,20 @@ class CustomizationTest extends Specification {
101101 then :
102102 result. task(" :app:test" ). outcome == TaskOutcome . SUCCESS
103103 }
104+
105+ def " build does not fail when JUnit has no version and the test folder is empty" () {
106+ given :
107+ appTestModuleInfoFile. parentFile. deleteDir()
108+ appBuildFile << '''
109+ testing.suites.withType<JvmTestSuite>().all {
110+ useJUnitJupiter("") // <- no version, we want to manage that ourselves
111+ }
112+ '''
113+
114+ when :
115+ def result = runTests()
116+
117+ then :
118+ result. task(" :app:test" ). outcome == TaskOutcome . NO_SOURCE
119+ }
104120}
You can’t perform that action at this time.
0 commit comments