From fd20b2fba6002de750f90e37d7e9e99fcd0fe505 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jun 2025 00:21:54 +0800 Subject: [PATCH 1/3] Add Gradle 8.3 into test matrix --- .github/workflows/ci.yml | 8 +++++++- build.gradle.kts | 6 ++++++ .../shadow/docs/executer/GradleBuildExecuter.groovy | 6 +++++- .../gradle/plugins/shadow/util/PluginSpecification.groovy | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62b54a091..10e3131ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,12 @@ jobs: os: [ ubuntu-latest, windows-latest ] # Always test on the latest version and some LTS. java: [ 17, 21, 24 ] + # Test on the minimum Gradle version and the latest. + gradle: [ 8.3, current ] + exclude: + # Gradle 8.3 doesn't support Java 24. + - gradle: 8.3 + java: 24 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -22,7 +28,7 @@ jobs: distribution: 'zulu' java-version: ${{ matrix.java }} - uses: gradle/actions/setup-gradle@v4 - - run: ./gradlew build + - run: ./gradlew build "-PtestGradleVersion=${{ matrix.gradle }}" publish-snapshot: needs: build diff --git a/build.gradle.kts b/build.gradle.kts index cc5c7ccce..cf83f8152 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -111,6 +111,12 @@ val isCI = providers.environmentVariable("CI").isPresent tasks.withType().configureEach { useJUnitPlatform() + val testGradleVersion = providers.gradleProperty("testGradleVersion").orNull.let { + if (it == null || it == "current") GradleVersion.current().version else it + } + logger.info("Using test Gradle version: $testGradleVersion") + systemProperty("TEST_GRADLE_VERSION", testGradleVersion) + maxParallelForks = Runtime.getRuntime().availableProcessors() if (isCI) { diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/executer/GradleBuildExecuter.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/executer/GradleBuildExecuter.groovy index 5e5bfd63e..579e7dc5f 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/executer/GradleBuildExecuter.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/docs/executer/GradleBuildExecuter.groovy @@ -54,7 +54,11 @@ include 'api', 'main' buildFile.text = replaceTokens(fullSnippet) - GradleRunner runner = GradleRunner.create().withProjectDir(tempDir).withPluginClasspath().forwardOutput() + GradleRunner runner = GradleRunner.create() + .withGradleVersion(PluginSpecification.TEST_GRADLE_VERSION) + .withProjectDir(tempDir) + .withPluginClasspath() + .forwardOutput() runner.withArguments(":main:build", "-m").build() diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy index 04514ec69..aa7d6967c 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/util/PluginSpecification.groovy @@ -18,6 +18,8 @@ abstract class PluginSpecification extends Specification { public static final String SHADOW_VERSION = System.getProperty("shadowVersion") + public static final String TEST_GRADLE_VERSION = System.getProperty("TEST_GRADLE_VERSION") + AppendableMavenFileRepository repo def setup() { @@ -55,6 +57,7 @@ abstract class PluginSpecification extends Specification { GradleRunner getRunner() { GradleRunner.create() + .withGradleVersion(TEST_GRADLE_VERSION) .withProjectDir(dir.toFile()) .forwardOutput() .withPluginClasspath() From 37546c395fe0c4a803fe015f251f81ce06d4b887 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jun 2025 00:33:52 +0800 Subject: [PATCH 2/3] Compat `RelocationUtil#configureRelocation` for Groovy 3 and 4 --- .../gradle/plugins/shadow/internal/RelocationUtil.groovy | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/RelocationUtil.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/RelocationUtil.groovy index f94ab89ed..f3d55385b 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/RelocationUtil.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/RelocationUtil.groovy @@ -12,7 +12,10 @@ class RelocationUtil { JarFile jf = new JarFile(jar) jf.entries().each { entry -> if (entry.name.endsWith(".class") && entry.name != "module-info.class") { - packages << entry.name[0..entry.name.lastIndexOf('/') - 1].replaceAll('/', '.') + def i = entry.name.lastIndexOf('/') + if (i != -1) { + packages << entry.name.take(i).replaceAll('/', '.') + } } } jf.close() From 34f03f7ee54562306b15222974c76b21c15de0f2 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 24 Jun 2025 00:35:11 +0800 Subject: [PATCH 3/3] Log info --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10e3131ba..09a95beb4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: distribution: 'zulu' java-version: ${{ matrix.java }} - uses: gradle/actions/setup-gradle@v4 - - run: ./gradlew build "-PtestGradleVersion=${{ matrix.gradle }}" + - run: ./gradlew build --info "-PtestGradleVersion=${{ matrix.gradle }}" publish-snapshot: needs: build