66import org .gradle .api .logging .Logging ;
77import org .gradle .testkit .runner .BuildResult ;
88import org .gradle .testkit .runner .GradleRunner ;
9- import org .gradle .util .GradleVersion ;
109import org .junit .jupiter .api .BeforeEach ;
10+ import org .junit .jupiter .api .Test ;
11+ import org .junitpioneer .jupiter .CartesianEnumSource ;
1112import org .junitpioneer .jupiter .CartesianProductTest ;
1213import org .junitpioneer .jupiter .CartesianValueSource ;
1314
2223
2324import static org .junit .jupiter .api .Assertions .*;
2425
26+ /**
27+ * If you're locally seeing the error:
28+ * {@code Could not create an instance of type org.gradle.initialization.DefaultSettings_Decorated.}
29+ * when running these test it will because you're using a recent version of Java and running into:
30+ * https://github.com/gradle/gradle/issues/10248.
31+ *
32+ * <p>Either switch to pre JDK-14 or <b>locally</b> comment out v5_1 and v5_2 in the {@link GradleVersion} enum.
33+ */
2534@ SuppressWarnings ("ConstantConditions" )
2635class ModulePluginSmokeTest {
2736 private static final Logger LOGGER = Logging .getLogger (ModulePluginSmokeTest .class );
2837
2938 private List <File > pluginClasspath ;
3039
40+ @ SuppressWarnings ("unused" )
41+ private enum GradleVersion {
42+ // Locally comment out the 5.x versions if running JDK-14+
43+ v5_1 , v5_6 ,
44+ v6_3 , v6_4_1 , v6_5_1 , v6_8_3 ,
45+ v7_0 , v7_2
46+ ;
47+
48+ @ Override
49+ public String toString () {
50+ return name ().substring (1 ).replaceAll ("_" , "." );
51+ }
52+ }
53+
54+ @ SuppressWarnings ("UnstableApiUsage" )
3155 @ BeforeEach
3256 void before () throws IOException {
3357 pluginClasspath = Resources .readLines (Resources .getResource ("plugin-classpath.txt" ), Charsets .UTF_8 )
@@ -38,38 +62,38 @@ void before() throws IOException {
3862
3963 @ CartesianProductTest (name = "smokeTest({arguments})" )
4064 @ CartesianValueSource (strings = {"test-project" , "test-project-kotlin-pre-1-7" , "test-project-kotlin" , "test-project-groovy" })
41- @ CartesianValueSource ( strings = { "5.1" , "5.6" , "6.3" , "6.4.1" , "6.5.1" , "6.8.3" , "7.0" , "7.2" } )
42- void smokeTest (String projectName , String gradleVersion ) {
65+ @ CartesianEnumSource ( GradleVersion . class )
66+ void smokeTest (String projectName , GradleVersion gradleVersion ) {
4367 LOGGER .lifecycle ("Executing smokeTest of {} with Gradle {}" , projectName , gradleVersion );
4468 if (!checkCombination (projectName , gradleVersion )) return ;
4569 var result = GradleRunner .create ()
4670 .withProjectDir (new File (projectName + "/" ))
4771 .withPluginClasspath (pluginClasspath )
48- .withGradleVersion (gradleVersion )
72+ .withGradleVersion (gradleVersion . toString () )
4973 .withArguments ("-c" , "smoke_test_settings.gradle" , "clean" , "build" , "run" , "--stacktrace" )
5074 .forwardOutput ()
5175 .build ();
5276
5377 assertTasksSuccessful (result , "greeter.api" , "build" );
5478 assertTasksSuccessful (result , "greeter.provider" , "build" );
5579 assertTasksSuccessful (result , "greeter.provider.test" , "build" );
56- if (GradleVersion .version (gradleVersion ) .compareTo (GradleVersion .version ("5.6" )) >= 0 ) {
80+ if (org . gradle . util . GradleVersion .version (gradleVersion . toString ()) .compareTo (org . gradle . util . GradleVersion .version ("5.6" )) >= 0 ) {
5781 assertTasksSuccessful (result , "greeter.provider.testfixture" , "build" );
5882 }
5983 assertTasksSuccessful (result , "greeter.runner" , "build" , "run" );
6084 }
6185
6286 @ CartesianProductTest (name = "smokeTestRun({arguments})" )
6387 @ CartesianValueSource (strings = {"test-project" , "test-project-kotlin-pre-1-7" , "test-project-kotlin" , "test-project-groovy" })
64- @ CartesianValueSource ( strings = { "5.1" , "5.6" , "6.3" , "6.4.1" , "6.5.1" , "6.8.3" , "7.0" , "7.2" } )
65- void smokeTestRun (String projectName , String gradleVersion ) {
88+ @ CartesianEnumSource ( GradleVersion . class )
89+ void smokeTestRun (String projectName , GradleVersion gradleVersion ) {
6690 LOGGER .lifecycle ("Executing smokeTestRun of {} with Gradle {}" , projectName , gradleVersion );
6791 if (!checkCombination (projectName , gradleVersion )) return ;
6892 var writer = new StringWriter (256 );
6993 var result = GradleRunner .create ()
7094 .withProjectDir (new File (projectName + "/" ))
7195 .withPluginClasspath (pluginClasspath )
72- .withGradleVersion (gradleVersion )
96+ .withGradleVersion (gradleVersion . toString () )
7397 .withArguments ("-q" , "-c" , "smoke_test_settings.gradle" , "clean" , ":greeter.runner:run" , "--args" , "aaa bbb" )
7498 .forwardStdOutput (writer )
7599 .forwardStdError (writer )
@@ -83,19 +107,18 @@ void smokeTestRun(String projectName, String gradleVersion) {
83107 assertEquals ("welcome" , lines .get (2 ));
84108 }
85109
86-
87110 @ CartesianProductTest (name = "smokeTestJunit5({arguments})" )
88111 @ CartesianValueSource (strings = {"5.4.2/1.4.2" , "5.5.2/1.5.2" , "5.7.1/1.7.1" })
89- @ CartesianValueSource ( strings = { "5.1" , "5.6" , "6.3" , "6.4.1" , "6.5.1" , "6.8.3" , "7.0" , "7.2" } )
90- void smokeTestJunit5 (String junitVersionPair , String gradleVersion ) {
112+ @ CartesianEnumSource ( GradleVersion . class )
113+ void smokeTestJunit5 (String junitVersionPair , GradleVersion gradleVersion ) {
91114 LOGGER .lifecycle ("Executing smokeTestJunit5 with junitVersionPair {} and Gradle {}" , junitVersionPair , gradleVersion );
92115 var junitVersionParts = junitVersionPair .split ("/" );
93116 var junitVersionProperty = String .format ("-PjUnitVersion=%s" , junitVersionParts [0 ]);
94117 var junitPlatformVersionProperty = String .format ("-PjUnitPlatformVersion=%s" , junitVersionParts [1 ]);
95118 var result = GradleRunner .create ()
96119 .withProjectDir (new File ("test-project/" ))
97120 .withPluginClasspath (pluginClasspath )
98- .withGradleVersion (gradleVersion )
121+ .withGradleVersion (gradleVersion . toString () )
99122 .withArguments ("-c" , "smoke_test_settings.gradle" , junitVersionProperty , junitPlatformVersionProperty , "clean" , "build" , "run" , "--stacktrace" )
100123 .forwardOutput ()
101124 .build ();
@@ -107,13 +130,13 @@ void smokeTestJunit5(String junitVersionPair, String gradleVersion) {
107130 }
108131
109132 @ CartesianProductTest (name = "smokeTestMixed({arguments})" )
110- @ CartesianValueSource ( strings = { "5.1" , "5.6" , "6.3" , "6.4.1" , "6.5.1" , "6.8.3" , "7.0" , "7.2" } )
111- void smokeTestMixed (String gradleVersion ) {
133+ @ CartesianEnumSource ( GradleVersion . class )
134+ void smokeTestMixed (GradleVersion gradleVersion ) {
112135 LOGGER .lifecycle ("Executing smokeTestMixed with Gradle {}" , gradleVersion );
113136 var result = GradleRunner .create ()
114137 .withProjectDir (new File ("test-project-mixed" ))
115138 .withPluginClasspath (pluginClasspath )
116- .withGradleVersion (gradleVersion )
139+ .withGradleVersion (gradleVersion . toString () )
117140 .withArguments ("-c" , "smoke_test_settings.gradle" , "clean" , "build" , "--stacktrace" )
118141 .forwardOutput ()
119142 .build ();
@@ -159,14 +182,14 @@ private static void assertExpectedClassFileFormats(
159182
160183 @ CartesianProductTest (name = "smokeTestDist({arguments})" )
161184 @ CartesianValueSource (strings = {"test-project" , "test-project-kotlin-pre-1-7" , "test-project-kotlin" , "test-project-groovy" })
162- @ CartesianValueSource ( strings = { "5.1" , "5.6" , "6.3" , "6.4.1" , "6.5.1" , "6.8.3" , "7.0" , "7.2" } )
163- void smokeTestDist (String projectName , String gradleVersion ) {
185+ @ CartesianEnumSource ( GradleVersion . class )
186+ void smokeTestDist (String projectName , GradleVersion gradleVersion ) {
164187 LOGGER .lifecycle ("Executing smokeTestDist of {} with Gradle {}" , projectName , gradleVersion );
165188 if (!checkCombination (projectName , gradleVersion )) return ;
166189 var result = GradleRunner .create ()
167190 .withProjectDir (new File (projectName + "/" ))
168191 .withPluginClasspath (pluginClasspath )
169- .withGradleVersion (gradleVersion )
192+ .withGradleVersion (gradleVersion . toString () )
170193 .withArguments ("-c" , "smoke_test_settings.gradle" , "clean" , "build" , ":greeter.runner:installDist" , "--stacktrace" )
171194 .forwardOutput ()
172195 .build ();
@@ -200,14 +223,14 @@ void smokeTestDist(String projectName, String gradleVersion) {
200223
201224 @ CartesianProductTest (name = "smokeTestRunDemo({arguments})" )
202225 @ CartesianValueSource (strings = {"test-project" , "test-project-kotlin-pre-1-7" , "test-project-kotlin" , "test-project-groovy" })
203- @ CartesianValueSource ( strings = { "5.1" , "5.6" , "6.3" , "6.4.1" , "6.5.1" , "6.8.3" , "7.0" , "7.2" } )
204- void smokeTestRunDemo (String projectName , String gradleVersion ) {
226+ @ CartesianEnumSource ( GradleVersion . class )
227+ void smokeTestRunDemo (String projectName , GradleVersion gradleVersion ) {
205228 LOGGER .lifecycle ("Executing smokeTestRunDemo of {} with Gradle {}" , projectName , gradleVersion );
206229 if (!checkCombination (projectName , gradleVersion )) return ;
207230 var result = GradleRunner .create ()
208231 .withProjectDir (new File (projectName + "/" ))
209232 .withPluginClasspath (pluginClasspath )
210- .withGradleVersion (gradleVersion )
233+ .withGradleVersion (gradleVersion . toString () )
211234 .withArguments ("-c" , "smoke_test_settings.gradle" , "clean" , "build" ,
212235 ":greeter.javaexec:runDemo1" , ":greeter.javaexec:runDemo2" , "--info" , "--stacktrace" )
213236 .forwardOutput ()
@@ -219,14 +242,14 @@ void smokeTestRunDemo(String projectName, String gradleVersion) {
219242
220243 @ CartesianProductTest (name = "smokeTestRunStartScripts({arguments})" )
221244 @ CartesianValueSource (strings = {"test-project" , "test-project-kotlin-pre-1-7" , "test-project-kotlin" , "test-project-groovy" })
222- @ CartesianValueSource ( strings = { "5.1" , "5.6" , "6.3" , "6.4.1" , "6.5.1" , "6.8.3" , "7.0" , "7.2" } )
223- void smokeTestRunStartScripts (String projectName , String gradleVersion ) {
245+ @ CartesianEnumSource ( GradleVersion . class )
246+ void smokeTestRunStartScripts (String projectName , GradleVersion gradleVersion ) {
224247 LOGGER .lifecycle ("Executing smokeTestRunScripts of {} with Gradle {}" , projectName , gradleVersion );
225248 if (!checkCombination (projectName , gradleVersion )) return ;
226249 var result = GradleRunner .create ()
227250 .withProjectDir (new File (projectName + "/" ))
228251 .withPluginClasspath (pluginClasspath )
229- .withGradleVersion (gradleVersion )
252+ .withGradleVersion (gradleVersion . toString () )
230253 .withArguments ("-c" , "smoke_test_settings.gradle" , "clean" , ":greeter.startscripts:installDist" , "--info" , "--stacktrace" )
231254 .forwardOutput ()
232255 .build ();
@@ -241,15 +264,20 @@ void smokeTestRunStartScripts(String projectName, String gradleVersion) {
241264 assertEquals ("Demo2: welcome home, Alice and Bob!" , ctx .getAppOutput ("demo2" ));
242265 }
243266
267+ @ Test
268+ void shouldNotCheckInWithCommentedOutVersions () {
269+ assertEquals (8 , GradleVersion .values ().length );
270+ }
271+
244272 private static void assertTasksSuccessful (BuildResult result , String subprojectName , String ... taskNames ) {
245273 for (String taskName : taskNames ) {
246274 SmokeTestHelper .assertTaskSuccessful (result , subprojectName , taskName );
247275 }
248276 }
249277
250- private static boolean checkCombination (String projectName , String gradleVersion ) {
251- final boolean kotlin_NotSupported = projectName .startsWith ("test-project-kotlin" ) && gradleVersion .compareTo ("6.4" ) < 0 ;
252- final boolean kotlin1_7_NotSupported = projectName .equals ("test-project-kotlin" ) && gradleVersion .compareTo ("6.6" ) < 0 ;
278+ private static boolean checkCombination (String projectName , GradleVersion gradleVersion ) {
279+ final boolean kotlin_NotSupported = projectName .startsWith ("test-project-kotlin" ) && gradleVersion .toString (). compareTo ("6.4" ) < 0 ;
280+ final boolean kotlin1_7_NotSupported = projectName .equals ("test-project-kotlin" ) && gradleVersion .toString (). compareTo ("6.6" ) < 0 ;
253281 if (kotlin_NotSupported || kotlin1_7_NotSupported ) {
254282 LOGGER .lifecycle ("Unsupported combination: {} / Gradle {}. Test skipped" , projectName , gradleVersion );
255283 return false ;
0 commit comments