Skip to content

Commit

Permalink
Update tests to cover Gradle 8
Browse files Browse the repository at this point in the history
fixes: #260
  • Loading branch information
big-andy-coates committed Feb 22, 2024
1 parent 915e595 commit fe2dbbb
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 60 deletions.
26 changes: 6 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,12 @@ An example application using this plugin is available [here](https://github.com/
Compatability
===

The plugin is compatible with the following Gradle versions:

| Gradle version | Min plugin version |
|----------------|----------------------------------------------------------------------------------------|
| 5.* -> 7.5.+ | 1.+ |
| 7.6+ | 1.8.14 |
| 8.+ | See [issue #260](https://github.com/java9-modularity/gradle-modules-plugin/issues/260) |

The plugin is compatible with the following Java versions:

| Java version | Min plugin version |
|--------------|--------------------|
| 11+ | 1.+ |

The plugin is compatible with the following Kotlin versions:

| Kotlin version | Min plugin version |
|----------------|--------------------|
| 1.0.* -> 1.6.* | 1.+ |
| 1.7+ | 1.8.12 |
| Plugin Version | Gradle Versions | Java Version | Kotlin Version | Notes |
|--------------------|-----------------|--------------|----------------|--------------------------------------------------------------------------------------------|
| - -> 1.18.12 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.6.+ | |
| 1.18.12 -> 1.18.13 | 5.+ -> 7.5.+ | 11+ | 1.0.+ -> 1.9.+ | Adds support for Kotlin 1.7 and above. |
| 1.18.14 | 5.+ -> 7.6.+ | 11+ | 1.0.+ -> 1.9.+ | Fixes compatibility issue with Gradle 7.6 |
| 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 |

Setup
===
Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ configurations {
compile.extendsFrom plugin
}

def jUnitVersion = '5.10.2'

dependencies {
implementation gradleApi()
implementation 'org.jooq:joor:0.9.15'
Expand All @@ -35,11 +37,11 @@ dependencies {
testImplementation gradleTestKit()
testImplementation 'com.google.guava:guava-base:r03'
testImplementation 'com.google.guava:guava-io:r03'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.2'
testImplementation "org.junit.jupiter:junit-jupiter-api:$jUnitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-params:$jUnitVersion"
testImplementation 'org.junit-pioneer:junit-pioneer:2.2.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.10.2' // required when testing in Eclipse
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$jUnitVersion"
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' // required when testing in Eclipse
}

shadowJar {
Expand All @@ -57,7 +59,7 @@ shadowJar {
jar.enabled = false
jar.dependsOn shadowJar

processResources.duplicatesStrategy = 'exclude'
processResources.duplicatesStrategy = DuplicatesStrategy.EXCLUDE

configurations {
[apiElements, runtimeElements].each {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

private List<File> pluginClasspath;

@SuppressWarnings("unused")
private enum GradleVersion {
v5_1, v5_6,
v6_3, v6_4_1, v6_5_1, v6_8_3,
v7_0, v7_6_4
v7_0, v7_6_4,
v8_0, v8_6
;

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

@CartesianTest(name = "smokeTest({arguments})")
void smokeTest(
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
@CartesianTest.Values(strings = {
"test-project",
"test-project-kotlin-pre-1-7",
"test-project-kotlin",
"test-project-groovy"
}) String projectName,
@CartesianTest.Enum GradleVersion gradleVersion) {
LOGGER.lifecycle("Executing smokeTest of {} with Gradle {}", projectName, gradleVersion);
assumeTrue(jdkSupported(gradleVersion));
assumeTrue(checkCombination(projectName, gradleVersion));
assumeTrue(checkKotlinCombination(projectName, gradleVersion));
var result = GradleRunner.create()
.withProjectDir(new File(projectName + "/"))
.withPluginClasspath(pluginClasspath)
Expand All @@ -77,11 +86,16 @@ void smokeTest(

@CartesianTest(name = "smokeTestRun({arguments})")
void smokeTestRun(
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
@CartesianTest.Values(strings = {
"test-project",
"test-project-kotlin-pre-1-7",
"test-project-kotlin",
"test-project-groovy"
}) String projectName,
@CartesianTest.Enum GradleVersion gradleVersion) {
LOGGER.lifecycle("Executing smokeTestRun of {} with Gradle {}", projectName, gradleVersion);
assumeTrue(jdkSupported(gradleVersion));
assumeTrue(checkCombination(projectName, gradleVersion));
assumeTrue(checkKotlinCombination(projectName, gradleVersion));
var writer = new StringWriter(256);
var result = GradleRunner.create()
.withProjectDir(new File(projectName + "/"))
Expand All @@ -102,12 +116,20 @@ void smokeTestRun(

@CartesianTest(name = "smokeTestJunit5({arguments})")
void smokeTestJunit5(
@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,
@CartesianTest.Values(strings = {
"5.4.2/1.4.2",
"5.5.2/1.5.2",
"5.7.1/1.7.1",
"5.8.0/1.8.0",
"5.10.2/1.10.2"
}) String junitVersionPair,
@CartesianTest.Enum GradleVersion gradleVersion) {
LOGGER.lifecycle("Executing smokeTestJunit5 with junitVersionPair {} and Gradle {}", junitVersionPair, gradleVersion);
assumeTrue(jdkSupported(gradleVersion));
var junitVersionParts = junitVersionPair.split("/");
var junitVersionProperty = String.format("-PjUnitVersion=%s", junitVersionParts[0]);
final String junitVersion = junitVersionParts[0];
assumeTrue(checkJUnitCombination(junitVersion, gradleVersion));
var junitVersionProperty = String.format("-PjUnitVersion=%s", junitVersion);
var junitPlatformVersionProperty = String.format("-PjUnitPlatformVersion=%s", junitVersionParts[1]);
var result = GradleRunner.create()
.withProjectDir(new File("test-project/"))
Expand Down Expand Up @@ -176,11 +198,16 @@ private static void assertExpectedClassFileFormats(

@CartesianTest(name = "smokeTestDist({arguments})")
void smokeTestDist(
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
@CartesianTest.Values(strings = {
"test-project",
"test-project-kotlin-pre-1-7",
"test-project-kotlin",
"test-project-groovy"
}) String projectName,
@CartesianTest.Enum GradleVersion gradleVersion) {
LOGGER.lifecycle("Executing smokeTestDist of {} with Gradle {}", projectName, gradleVersion);
assumeTrue(jdkSupported(gradleVersion));
assumeTrue(checkCombination(projectName, gradleVersion));
assumeTrue(checkKotlinCombination(projectName, gradleVersion));
var result = GradleRunner.create()
.withProjectDir(new File(projectName + "/"))
.withPluginClasspath(pluginClasspath)
Expand Down Expand Up @@ -218,11 +245,16 @@ void smokeTestDist(

@CartesianTest(name = "smokeTestRunDemo({arguments})")
void smokeTestRunDemo(
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
@CartesianTest.Values(strings = {
"test-project",
"test-project-kotlin-pre-1-7",
"test-project-kotlin",
"test-project-groovy"
}) String projectName,
@CartesianTest.Enum GradleVersion gradleVersion) {
LOGGER.lifecycle("Executing smokeTestRunDemo of {} with Gradle {}", projectName, gradleVersion);
assumeTrue(jdkSupported(gradleVersion));
assumeTrue(checkCombination(projectName, gradleVersion));
assumeTrue(checkKotlinCombination(projectName, gradleVersion));
var result = GradleRunner.create()
.withProjectDir(new File(projectName + "/"))
.withPluginClasspath(pluginClasspath)
Expand All @@ -238,11 +270,16 @@ void smokeTestRunDemo(

@CartesianTest(name = "smokeTestRunStartScripts({arguments})")
void smokeTestRunStartScripts(
@CartesianTest.Values(strings = {"test-project", "test-project-kotlin-pre-1-7", "test-project-kotlin", "test-project-groovy"}) String projectName,
@CartesianTest.Values(strings = {
"test-project",
"test-project-kotlin-pre-1-7",
"test-project-kotlin",
"test-project-groovy"
}) String projectName,
@CartesianTest.Enum GradleVersion gradleVersion) {
LOGGER.lifecycle("Executing smokeTestRunScripts of {} with Gradle {}", projectName, gradleVersion);
assumeTrue(jdkSupported(gradleVersion));
assumeTrue(checkCombination(projectName, gradleVersion));
assumeTrue(checkKotlinCombination(projectName, gradleVersion));
var result = GradleRunner.create()
.withProjectDir(new File(projectName + "/"))
.withPluginClasspath(pluginClasspath)
Expand All @@ -263,7 +300,7 @@ void smokeTestRunStartScripts(

@Test
void shouldNotCheckInWithCommentedOutVersions() {
assertEquals(8, GradleVersion.values().length);
assertEquals(10, GradleVersion.values().length);
}

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

private static boolean checkCombination(String projectName, GradleVersion gradleVersion) {
private static boolean checkKotlinCombination(String projectName, GradleVersion gradleVersion) {
final boolean kotlin_NotSupported = projectName.startsWith("test-project-kotlin") && gradleVersion.toString().compareTo("6.4") < 0;
final boolean kotlin1_7_NotSupported = projectName.equals("test-project-kotlin") && gradleVersion.toString().compareTo("6.6") < 0;
if (kotlin_NotSupported || kotlin1_7_NotSupported) {
final boolean kotlinPost1_7_NotSupported = projectName.equals("test-project-kotlin") && gradleVersion.toString().compareTo("6.6") < 0;
final boolean kotlinPre1_7_NotSupported = projectName.equals("test-project-kotlin-pre-1-7") && gradleVersion.toString().compareTo("8.0") >= 0;
if (kotlin_NotSupported || kotlinPost1_7_NotSupported || kotlinPre1_7_NotSupported) {
LOGGER.lifecycle("Unsupported combination: {} / Gradle {}. Test skipped", projectName, gradleVersion);
return false;
}
return true;
}

private boolean checkJUnitCombination(final String junitVersion, final GradleVersion gradleVersion) {
final boolean gradleEighthPlus = gradleVersion.ordinal() >= GradleVersion.v8_0.ordinal();
final Matcher m = SEMANTIC_VERSION.matcher(junitVersion);
assumeTrue(m.matches(), "JUnit version not semantic: " + junitVersion);
final boolean junitOlderThan5_8_0 = Integer.parseInt(m.group("major")) < 5 ||
(Integer.parseInt(m.group("major")) == 5 && Integer.parseInt(m.group("minor")) < 8);

if (gradleEighthPlus && junitOlderThan5_8_0) {
LOGGER.lifecycle("Unsupported JUnit and Gradle combination. Gradle: {}, JUnit: {}: Test skipped", gradleVersion, junitVersion);
return false;
}
return true;
}

private static int javaMajorVersion() {
final String version = System.getProperty("java.version");
return Integer.parseInt(version.substring(0, version.indexOf(".")));
Expand All @@ -301,7 +353,7 @@ private boolean jdkSupported(final GradleVersion gradleVersion) {
case v5_1:
case v5_6:
final int major = javaMajorVersion();
if (major >= 14) {
if (major > 13) {
LOGGER.lifecycle("Unsupported JDK version '{}' for Gradle 5: Test skipped", major);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions test-project-groovy/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jUnitVersion = 5.6.2
jUnitPlatformVersion = 1.6.2
jUnitVersion = 5.10.2
jUnitPlatformVersion = 1.10.2
5 changes: 5 additions & 0 deletions test-project-kotlin-pre-1-7/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ plugins {
id("org.javamodularity.moduleplugin") version "1.8.14" apply false
}

if (gradle.gradleVersion >= "8.0") {
throw GradleException("The Kotlin version used in this build isn't compatible with Gradle 8. " +
"This project should be excluded when testing with Gradle version 8 and above.")
}

subprojects {
apply(plugin = "kotlin")
apply(plugin = "org.javamodularity.moduleplugin")
Expand Down
4 changes: 2 additions & 2 deletions test-project-kotlin-pre-1-7/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jUnitVersion = 5.6.2
jUnitPlatformVersion = 1.6.2
jUnitVersion = 5.10.2
jUnitPlatformVersion = 1.10.2
17 changes: 11 additions & 6 deletions test-project-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ subprojects {

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

val implementation by configurations
val testImplementation by configurations
Expand All @@ -23,9 +21,18 @@ subprojects {
//endregion

//region KOTLIN
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
if (gradle.gradleVersion >= "8.0") {
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
} else {
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
}
Expand Down Expand Up @@ -54,6 +61,4 @@ subprojects {
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$jUnitVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:$jUnitPlatformVersion")
}

// build.dependsOn(javadoc) // TODO: No public or protected classes found to document
}
4 changes: 2 additions & 2 deletions test-project-kotlin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jUnitVersion = 5.6.2
jUnitPlatformVersion = 1.6.2
jUnitVersion = 5.10.2
jUnitPlatformVersion = 1.10.2
7 changes: 6 additions & 1 deletion test-project-kotlin/greeter.startscripts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ File("${project.projectDir}/src/main/kotlin/startscripts")
val runDemo = tasks.create<ModularJavaExec>("run$demoClassName") {
group = "Demo"
description = "Run the $demoClassName program"
main = "$moduleName/startscripts.${demoClassName}Kt"
if (gradle.gradleVersion >= "8.0") {
mainClass.set("startscripts.${demoClassName}Kt")
mainModule.set(moduleName)
} else {
main = "$moduleName/startscripts.${demoClassName}Kt"
}
jvmArgs = listOf("-Xmx128m")
}

Expand Down
4 changes: 2 additions & 2 deletions test-project-mixed/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jUnitVersion = 5.6.2
jUnitPlatformVersion = 1.6.2
jUnitVersion = 5.10.2
jUnitPlatformVersion = 1.10.2
4 changes: 2 additions & 2 deletions test-project/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jUnitVersion = 5.6.2
jUnitPlatformVersion = 1.6.2
jUnitVersion = 5.10.2
jUnitPlatformVersion = 1.10.2

0 comments on commit fe2dbbb

Please sign in to comment.