Skip to content

Commit 3de2cc0

Browse files
Extend test coverage to Gradle 7.6.4 + JUnit 5.10.2
+ JUnit Platform 1.10.2 + Update Gradle version used to build to 7.6.4
1 parent 1daf27d commit 3de2cc0

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/test/java/org/javamodularity/moduleplugin/ModulePluginSmokeTest.java

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,8 @@
2020
import java.util.stream.Stream;
2121

2222
import static org.junit.jupiter.api.Assertions.*;
23+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
2324

24-
/**
25-
* If you're locally seeing the error:
26-
* {@code Could not create an instance of type org.gradle.initialization.DefaultSettings_Decorated.}
27-
* when running these test it will because you're using a recent version of Java and running into:
28-
* https://github.com/gradle/gradle/issues/10248.
29-
*
30-
* <p>Either switch to pre JDK-14 or <b>locally</b> comment out v5_1 and v5_2 in the {@link GradleVersion} enum.
31-
*/
3225
@SuppressWarnings("ConstantConditions")
3326
class ModulePluginSmokeTest {
3427
private static final Logger LOGGER = Logging.getLogger(ModulePluginSmokeTest.class);
@@ -37,10 +30,9 @@ class ModulePluginSmokeTest {
3730

3831
@SuppressWarnings("unused")
3932
private enum GradleVersion {
40-
// Locally comment out the 5.x versions if running JDK-14+
4133
v5_1, v5_6,
4234
v6_3, v6_4_1, v6_5_1, v6_8_3,
43-
v7_0, v7_2
35+
v7_0, v7_6_4
4436
;
4537

4638
@Override
@@ -63,7 +55,8 @@ void smokeTest(
6355
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
6456
@CartesianTest.Enum GradleVersion gradleVersion) {
6557
LOGGER.lifecycle("Executing smokeTest of {} with Gradle {}", projectName, gradleVersion);
66-
if(!checkCombination(projectName, gradleVersion)) return;
58+
assumeTrue(jdkSupported(gradleVersion));
59+
assumeTrue(checkCombination(projectName, gradleVersion));
6760
var result = GradleRunner.create()
6861
.withProjectDir(new File(projectName + "/"))
6962
.withPluginClasspath(pluginClasspath)
@@ -87,7 +80,8 @@ void smokeTestRun(
8780
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
8881
@CartesianTest.Enum GradleVersion gradleVersion) {
8982
LOGGER.lifecycle("Executing smokeTestRun of {} with Gradle {}", projectName, gradleVersion);
90-
if(!checkCombination(projectName, gradleVersion)) return;
83+
assumeTrue(jdkSupported(gradleVersion));
84+
assumeTrue(checkCombination(projectName, gradleVersion));
9185
var writer = new StringWriter(256);
9286
var result = GradleRunner.create()
9387
.withProjectDir(new File(projectName + "/"))
@@ -108,9 +102,10 @@ void smokeTestRun(
108102

109103
@CartesianTest(name = "smokeTestJunit5({arguments})")
110104
void smokeTestJunit5(
111-
@CartesianTest.Values(strings = {"5.4.2/1.4.2", "5.5.2/1.5.2", "5.7.1/1.7.1"}) String junitVersionPair,
105+
@CartesianTest.Values(strings = {"5.4.2/1.4.2", "5.5.2/1.5.2", "5.7.1/1.7.1", "5.10.2/1.10.2"}) String junitVersionPair,
112106
@CartesianTest.Enum GradleVersion gradleVersion) {
113107
LOGGER.lifecycle("Executing smokeTestJunit5 with junitVersionPair {} and Gradle {}", junitVersionPair, gradleVersion);
108+
assumeTrue(jdkSupported(gradleVersion));
114109
var junitVersionParts = junitVersionPair.split("/");
115110
var junitVersionProperty = String.format("-PjUnitVersion=%s", junitVersionParts[0]);
116111
var junitPlatformVersionProperty = String.format("-PjUnitPlatformVersion=%s", junitVersionParts[1]);
@@ -131,6 +126,7 @@ void smokeTestJunit5(
131126
@CartesianTest(name = "smokeTestMixed({arguments})")
132127
void smokeTestMixed(@CartesianTest.Enum GradleVersion gradleVersion) {
133128
LOGGER.lifecycle("Executing smokeTestMixed with Gradle {}", gradleVersion);
129+
assumeTrue(jdkSupported(gradleVersion));
134130
var result = GradleRunner.create()
135131
.withProjectDir(new File("test-project-mixed"))
136132
.withPluginClasspath(pluginClasspath)
@@ -183,7 +179,8 @@ void smokeTestDist(
183179
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
184180
@CartesianTest.Enum GradleVersion gradleVersion) {
185181
LOGGER.lifecycle("Executing smokeTestDist of {} with Gradle {}", projectName, gradleVersion);
186-
if(!checkCombination(projectName, gradleVersion)) return;
182+
assumeTrue(jdkSupported(gradleVersion));
183+
assumeTrue(checkCombination(projectName, gradleVersion));
187184
var result = GradleRunner.create()
188185
.withProjectDir(new File(projectName + "/"))
189186
.withPluginClasspath(pluginClasspath)
@@ -224,7 +221,8 @@ void smokeTestRunDemo(
224221
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
225222
@CartesianTest.Enum GradleVersion gradleVersion) {
226223
LOGGER.lifecycle("Executing smokeTestRunDemo of {} with Gradle {}", projectName, gradleVersion);
227-
if(!checkCombination(projectName, gradleVersion)) return;
224+
assumeTrue(jdkSupported(gradleVersion));
225+
assumeTrue(checkCombination(projectName, gradleVersion));
228226
var result = GradleRunner.create()
229227
.withProjectDir(new File(projectName + "/"))
230228
.withPluginClasspath(pluginClasspath)
@@ -243,7 +241,8 @@ void smokeTestRunStartScripts(
243241
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
244242
@CartesianTest.Enum GradleVersion gradleVersion) {
245243
LOGGER.lifecycle("Executing smokeTestRunScripts of {} with Gradle {}", projectName, gradleVersion);
246-
if(!checkCombination(projectName, gradleVersion)) return;
244+
assumeTrue(jdkSupported(gradleVersion));
245+
assumeTrue(checkCombination(projectName, gradleVersion));
247246
var result = GradleRunner.create()
248247
.withProjectDir(new File(projectName + "/"))
249248
.withPluginClasspath(pluginClasspath)
@@ -264,7 +263,7 @@ void smokeTestRunStartScripts(
264263

265264
@Test
266265
void shouldNotCheckInWithCommentedOutVersions() {
267-
assertEquals(8, GradleVersion.values().length);
266+
assertEquals(10, GradleVersion.values().length);
268267
}
269268

270269
private static void assertTasksSuccessful(BuildResult result, String subprojectName, String... taskNames) {
@@ -287,4 +286,28 @@ private static boolean checkCombination(String projectName, GradleVersion gradle
287286
}
288287
return true;
289288
}
289+
290+
private static int javaMajorVersion() {
291+
final String version = System.getProperty("java.version");
292+
return Integer.parseInt(version.substring(0, version.indexOf(".")));
293+
}
294+
295+
private boolean jdkSupported(final GradleVersion gradleVersion) {
296+
switch (gradleVersion) {
297+
// CI build runs with early JDK that supports these Gradle version
298+
// But don't fail locally if running local JDK.
299+
// Running JDK 14+ with Gradle 5 runs into:
300+
// https://github.com/gradle/gradle/issues/10248
301+
case v5_1:
302+
case v5_6:
303+
final int major = javaMajorVersion();
304+
if (major >= 14) {
305+
LOGGER.lifecycle("Unsupported JDK version '{}' for Gradle 5: Test skipped", major);
306+
return false;
307+
}
308+
return true;
309+
default:
310+
return true;
311+
}
312+
}
290313
}

0 commit comments

Comments
 (0)