Skip to content

Commit 76c2e4e

Browse files
Merge pull request #264 from big-andy-coates/gradle8
Update tests to cover Gradle 8
2 parents 915e595 + fe2dbbb commit 76c2e4e

File tree

11 files changed

+115
-60
lines changed

11 files changed

+115
-60
lines changed

README.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,12 @@ An example application using this plugin is available [here](https://github.com/
3535
Compatability
3636
===
3737

38-
The plugin is compatible with the following Gradle versions:
39-
40-
| Gradle version | Min plugin version |
41-
|----------------|----------------------------------------------------------------------------------------|
42-
| 5.* -> 7.5.+ | 1.+ |
43-
| 7.6+ | 1.8.14 |
44-
| 8.+ | See [issue #260](https://github.com/java9-modularity/gradle-modules-plugin/issues/260) |
45-
46-
The plugin is compatible with the following Java versions:
47-
48-
| Java version | Min plugin version |
49-
|--------------|--------------------|
50-
| 11+ | 1.+ |
51-
52-
The plugin is compatible with the following Kotlin versions:
53-
54-
| Kotlin version | Min plugin version |
55-
|----------------|--------------------|
56-
| 1.0.* -> 1.6.* | 1.+ |
57-
| 1.7+ | 1.8.12 |
38+
| Plugin Version | Gradle Versions | Java Version | Kotlin Version | Notes |
39+
|--------------------|-----------------|--------------|----------------|--------------------------------------------------------------------------------------------|
40+
| - -> 1.18.12 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.6.+ | |
41+
| 1.18.12 -> 1.18.13 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.9.+ | Adds support for Kotlin 1.7 and above. |
42+
| 1.18.14 | 5.+ -> 7.6.+ | 11+ | 1.0.+ -> 1.9.+ | Fixes compatibility issue with Gradle 7.6 |
43+
| 1.18.15 -> + | 5.+ -> 8.6.+ | 11+ | 1.6.+ -> 1.9.+ | Fixes compatibility issues with Gradle 8.0.<br>Use JUnit v5.8.0 or above if using Gradle 8 |
5844

5945
Setup
6046
===

build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ configurations {
2727
compile.extendsFrom plugin
2828
}
2929

30+
def jUnitVersion = '5.10.2'
31+
3032
dependencies {
3133
implementation gradleApi()
3234
implementation 'org.jooq:joor:0.9.15'
@@ -35,11 +37,11 @@ dependencies {
3537
testImplementation gradleTestKit()
3638
testImplementation 'com.google.guava:guava-base:r03'
3739
testImplementation 'com.google.guava:guava-io:r03'
38-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
39-
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.2'
40+
testImplementation "org.junit.jupiter:junit-jupiter-api:$jUnitVersion"
41+
testImplementation "org.junit.jupiter:junit-jupiter-params:$jUnitVersion"
4042
testImplementation 'org.junit-pioneer:junit-pioneer:2.2.0'
41-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2'
42-
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.10.2' // required when testing in Eclipse
43+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jUnitVersion"
44+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' // required when testing in Eclipse
4345
}
4446

4547
shadowJar {
@@ -57,7 +59,7 @@ shadowJar {
5759
jar.enabled = false
5860
jar.dependsOn shadowJar
5961

60-
processResources.duplicatesStrategy = 'exclude'
62+
processResources.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
6163

6264
configurations {
6365
[apiElements, runtimeElements].each {

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

Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import java.nio.file.Path;
1717
import java.util.Arrays;
1818
import java.util.List;
19+
import java.util.regex.Matcher;
20+
import java.util.regex.Pattern;
1921
import java.util.stream.Collectors;
2022
import java.util.stream.Stream;
2123

@@ -25,14 +27,16 @@
2527
@SuppressWarnings("ConstantConditions")
2628
class ModulePluginSmokeTest {
2729
private static final Logger LOGGER = Logging.getLogger(ModulePluginSmokeTest.class);
30+
private static final Pattern SEMANTIC_VERSION = Pattern.compile("(?<major>\\d+)\\.(?<minor>\\d+).(?<patch>\\d+)");
2831

2932
private List<File> pluginClasspath;
3033

3134
@SuppressWarnings("unused")
3235
private enum GradleVersion {
3336
v5_1, v5_6,
3437
v6_3, v6_4_1, v6_5_1, v6_8_3,
35-
v7_0, v7_6_4
38+
v7_0, v7_6_4,
39+
v8_0, v8_6
3640
;
3741

3842
@Override
@@ -52,11 +56,16 @@ void before() throws IOException {
5256

5357
@CartesianTest(name = "smokeTest({arguments})")
5458
void smokeTest(
55-
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
59+
@CartesianTest.Values(strings = {
60+
"test-project",
61+
"test-project-kotlin-pre-1-7",
62+
"test-project-kotlin",
63+
"test-project-groovy"
64+
}) String projectName,
5665
@CartesianTest.Enum GradleVersion gradleVersion) {
5766
LOGGER.lifecycle("Executing smokeTest of {} with Gradle {}", projectName, gradleVersion);
5867
assumeTrue(jdkSupported(gradleVersion));
59-
assumeTrue(checkCombination(projectName, gradleVersion));
68+
assumeTrue(checkKotlinCombination(projectName, gradleVersion));
6069
var result = GradleRunner.create()
6170
.withProjectDir(new File(projectName + "/"))
6271
.withPluginClasspath(pluginClasspath)
@@ -77,11 +86,16 @@ void smokeTest(
7786

7887
@CartesianTest(name = "smokeTestRun({arguments})")
7988
void smokeTestRun(
80-
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
89+
@CartesianTest.Values(strings = {
90+
"test-project",
91+
"test-project-kotlin-pre-1-7",
92+
"test-project-kotlin",
93+
"test-project-groovy"
94+
}) String projectName,
8195
@CartesianTest.Enum GradleVersion gradleVersion) {
8296
LOGGER.lifecycle("Executing smokeTestRun of {} with Gradle {}", projectName, gradleVersion);
8397
assumeTrue(jdkSupported(gradleVersion));
84-
assumeTrue(checkCombination(projectName, gradleVersion));
98+
assumeTrue(checkKotlinCombination(projectName, gradleVersion));
8599
var writer = new StringWriter(256);
86100
var result = GradleRunner.create()
87101
.withProjectDir(new File(projectName + "/"))
@@ -102,12 +116,20 @@ void smokeTestRun(
102116

103117
@CartesianTest(name = "smokeTestJunit5({arguments})")
104118
void smokeTestJunit5(
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,
119+
@CartesianTest.Values(strings = {
120+
"5.4.2/1.4.2",
121+
"5.5.2/1.5.2",
122+
"5.7.1/1.7.1",
123+
"5.8.0/1.8.0",
124+
"5.10.2/1.10.2"
125+
}) String junitVersionPair,
106126
@CartesianTest.Enum GradleVersion gradleVersion) {
107127
LOGGER.lifecycle("Executing smokeTestJunit5 with junitVersionPair {} and Gradle {}", junitVersionPair, gradleVersion);
108128
assumeTrue(jdkSupported(gradleVersion));
109129
var junitVersionParts = junitVersionPair.split("/");
110-
var junitVersionProperty = String.format("-PjUnitVersion=%s", junitVersionParts[0]);
130+
final String junitVersion = junitVersionParts[0];
131+
assumeTrue(checkJUnitCombination(junitVersion, gradleVersion));
132+
var junitVersionProperty = String.format("-PjUnitVersion=%s", junitVersion);
111133
var junitPlatformVersionProperty = String.format("-PjUnitPlatformVersion=%s", junitVersionParts[1]);
112134
var result = GradleRunner.create()
113135
.withProjectDir(new File("test-project/"))
@@ -176,11 +198,16 @@ private static void assertExpectedClassFileFormats(
176198

177199
@CartesianTest(name = "smokeTestDist({arguments})")
178200
void smokeTestDist(
179-
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
201+
@CartesianTest.Values(strings = {
202+
"test-project",
203+
"test-project-kotlin-pre-1-7",
204+
"test-project-kotlin",
205+
"test-project-groovy"
206+
}) String projectName,
180207
@CartesianTest.Enum GradleVersion gradleVersion) {
181208
LOGGER.lifecycle("Executing smokeTestDist of {} with Gradle {}", projectName, gradleVersion);
182209
assumeTrue(jdkSupported(gradleVersion));
183-
assumeTrue(checkCombination(projectName, gradleVersion));
210+
assumeTrue(checkKotlinCombination(projectName, gradleVersion));
184211
var result = GradleRunner.create()
185212
.withProjectDir(new File(projectName + "/"))
186213
.withPluginClasspath(pluginClasspath)
@@ -218,11 +245,16 @@ void smokeTestDist(
218245

219246
@CartesianTest(name = "smokeTestRunDemo({arguments})")
220247
void smokeTestRunDemo(
221-
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
248+
@CartesianTest.Values(strings = {
249+
"test-project",
250+
"test-project-kotlin-pre-1-7",
251+
"test-project-kotlin",
252+
"test-project-groovy"
253+
}) String projectName,
222254
@CartesianTest.Enum GradleVersion gradleVersion) {
223255
LOGGER.lifecycle("Executing smokeTestRunDemo of {} with Gradle {}", projectName, gradleVersion);
224256
assumeTrue(jdkSupported(gradleVersion));
225-
assumeTrue(checkCombination(projectName, gradleVersion));
257+
assumeTrue(checkKotlinCombination(projectName, gradleVersion));
226258
var result = GradleRunner.create()
227259
.withProjectDir(new File(projectName + "/"))
228260
.withPluginClasspath(pluginClasspath)
@@ -238,11 +270,16 @@ void smokeTestRunDemo(
238270

239271
@CartesianTest(name = "smokeTestRunStartScripts({arguments})")
240272
void smokeTestRunStartScripts(
241-
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
273+
@CartesianTest.Values(strings = {
274+
"test-project",
275+
"test-project-kotlin-pre-1-7",
276+
"test-project-kotlin",
277+
"test-project-groovy"
278+
}) String projectName,
242279
@CartesianTest.Enum GradleVersion gradleVersion) {
243280
LOGGER.lifecycle("Executing smokeTestRunScripts of {} with Gradle {}", projectName, gradleVersion);
244281
assumeTrue(jdkSupported(gradleVersion));
245-
assumeTrue(checkCombination(projectName, gradleVersion));
282+
assumeTrue(checkKotlinCombination(projectName, gradleVersion));
246283
var result = GradleRunner.create()
247284
.withProjectDir(new File(projectName + "/"))
248285
.withPluginClasspath(pluginClasspath)
@@ -263,7 +300,7 @@ void smokeTestRunStartScripts(
263300

264301
@Test
265302
void shouldNotCheckInWithCommentedOutVersions() {
266-
assertEquals(8, GradleVersion.values().length);
303+
assertEquals(10, GradleVersion.values().length);
267304
}
268305

269306
private static void assertTasksSuccessful(BuildResult result, String subprojectName, String... taskNames) {
@@ -277,16 +314,31 @@ private static void assertOutputDoesNotContain(BuildResult result, String text)
277314
assertFalse(output.contains(text), "Output should not contain '" + text + "', but was: " + output);
278315
}
279316

280-
private static boolean checkCombination(String projectName, GradleVersion gradleVersion) {
317+
private static boolean checkKotlinCombination(String projectName, GradleVersion gradleVersion) {
281318
final boolean kotlin_NotSupported = projectName.startsWith("test-project-kotlin") && gradleVersion.toString().compareTo("6.4") < 0;
282-
final boolean kotlin1_7_NotSupported = projectName.equals("test-project-kotlin") && gradleVersion.toString().compareTo("6.6") < 0;
283-
if (kotlin_NotSupported || kotlin1_7_NotSupported) {
319+
final boolean kotlinPost1_7_NotSupported = projectName.equals("test-project-kotlin") && gradleVersion.toString().compareTo("6.6") < 0;
320+
final boolean kotlinPre1_7_NotSupported = projectName.equals("test-project-kotlin-pre-1-7") && gradleVersion.toString().compareTo("8.0") >= 0;
321+
if (kotlin_NotSupported || kotlinPost1_7_NotSupported || kotlinPre1_7_NotSupported) {
284322
LOGGER.lifecycle("Unsupported combination: {} / Gradle {}. Test skipped", projectName, gradleVersion);
285323
return false;
286324
}
287325
return true;
288326
}
289327

328+
private boolean checkJUnitCombination(final String junitVersion, final GradleVersion gradleVersion) {
329+
final boolean gradleEighthPlus = gradleVersion.ordinal() >= GradleVersion.v8_0.ordinal();
330+
final Matcher m = SEMANTIC_VERSION.matcher(junitVersion);
331+
assumeTrue(m.matches(), "JUnit version not semantic: " + junitVersion);
332+
final boolean junitOlderThan5_8_0 = Integer.parseInt(m.group("major")) < 5 ||
333+
(Integer.parseInt(m.group("major")) == 5 && Integer.parseInt(m.group("minor")) < 8);
334+
335+
if (gradleEighthPlus && junitOlderThan5_8_0) {
336+
LOGGER.lifecycle("Unsupported JUnit and Gradle combination. Gradle: {}, JUnit: {}: Test skipped", gradleVersion, junitVersion);
337+
return false;
338+
}
339+
return true;
340+
}
341+
290342
private static int javaMajorVersion() {
291343
final String version = System.getProperty("java.version");
292344
return Integer.parseInt(version.substring(0, version.indexOf(".")));
@@ -301,7 +353,7 @@ private boolean jdkSupported(final GradleVersion gradleVersion) {
301353
case v5_1:
302354
case v5_6:
303355
final int major = javaMajorVersion();
304-
if (major >= 14) {
356+
if (major > 13) {
305357
LOGGER.lifecycle("Unsupported JDK version '{}' for Gradle 5: Test skipped", major);
306358
return false;
307359
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
jUnitVersion = 5.6.2
2-
jUnitPlatformVersion = 1.6.2
1+
jUnitVersion = 5.10.2
2+
jUnitPlatformVersion = 1.10.2

test-project-kotlin-pre-1-7/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ plugins {
55
id("org.javamodularity.moduleplugin") version "1.8.14" apply false
66
}
77

8+
if (gradle.gradleVersion >= "8.0") {
9+
throw GradleException("The Kotlin version used in this build isn't compatible with Gradle 8. " +
10+
"This project should be excluded when testing with Gradle version 8 and above.")
11+
}
12+
813
subprojects {
914
apply(plugin = "kotlin")
1015
apply(plugin = "org.javamodularity.moduleplugin")
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
jUnitVersion = 5.6.2
2-
jUnitPlatformVersion = 1.6.2
1+
jUnitVersion = 5.10.2
2+
jUnitPlatformVersion = 1.10.2

test-project-kotlin/build.gradle.kts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ subprojects {
1111

1212
//region https://docs.gradle.org/current/userguide/kotlin_dsl.html#using_kotlin_delegated_properties
1313
val test by tasks.existing(Test::class)
14-
val build by tasks
15-
val javadoc by tasks
1614

1715
val implementation by configurations
1816
val testImplementation by configurations
@@ -23,9 +21,18 @@ subprojects {
2321
//endregion
2422

2523
//region KOTLIN
26-
tasks.withType<KotlinCompile> {
27-
kotlinOptions.jvmTarget = "1.8"
24+
if (gradle.gradleVersion >= "8.0") {
25+
configure<JavaPluginExtension> {
26+
toolchain {
27+
languageVersion.set(JavaLanguageVersion.of(11))
28+
}
29+
}
30+
} else {
31+
tasks.withType<KotlinCompile> {
32+
kotlinOptions.jvmTarget = "1.8"
33+
}
2834
}
35+
2936
dependencies {
3037
implementation(kotlin("stdlib-jdk8"))
3138
}
@@ -54,6 +61,4 @@ subprojects {
5461
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jUnitVersion")
5562
testRuntimeOnly("org.junit.platform:junit-platform-launcher:$jUnitPlatformVersion")
5663
}
57-
58-
// build.dependsOn(javadoc) // TODO: No public or protected classes found to document
5964
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
jUnitVersion = 5.6.2
2-
jUnitPlatformVersion = 1.6.2
1+
jUnitVersion = 5.10.2
2+
jUnitPlatformVersion = 1.10.2

test-project-kotlin/greeter.startscripts/build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ File("${project.projectDir}/src/main/kotlin/startscripts")
3535
val runDemo = tasks.create<ModularJavaExec>("run$demoClassName") {
3636
group = "Demo"
3737
description = "Run the $demoClassName program"
38-
main = "$moduleName/startscripts.${demoClassName}Kt"
38+
if (gradle.gradleVersion >= "8.0") {
39+
mainClass.set("startscripts.${demoClassName}Kt")
40+
mainModule.set(moduleName)
41+
} else {
42+
main = "$moduleName/startscripts.${demoClassName}Kt"
43+
}
3944
jvmArgs = listOf("-Xmx128m")
4045
}
4146

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
jUnitVersion = 5.6.2
2-
jUnitPlatformVersion = 1.6.2
1+
jUnitVersion = 5.10.2
2+
jUnitPlatformVersion = 1.10.2

0 commit comments

Comments
 (0)