Skip to content

Commit a0da04a

Browse files
authored
Make Shadow 8 be compatible with Gradle 9 (#1470)
* Bump https://docs.gradle.org/9.0.0-rc-1/release-notes.html * Mark `ShadowJar` as abstract * Remove Java 11 and add Java 24 into test matrix * Replace `SelfResolvingDependency` with `FileCollectionDependency` * Remove `ShadowCopyAction.ArchiveFileTreeElement.getMode` * Mark `JavaJarExec` as abstract * org.spockframework:spock-core:2.3-groovy-4.0 * Remove static for `TransformerTestSupport.transformer` * Replace `org.gradle.api.UncheckedIOException` * Compat `dependencyProject` * Replace `mainClassName` with `mainClass` for `CreateStartScripts` * Compat `RelativeArchivePath.getParent` for Groovy 3 and 4 * Annotate `RelocatorRemapper` with `CompileStatic` * Update changelog * Revert "Remove `ShadowCopyAction.ArchiveFileTreeElement.getMode`" This reverts commit 5b9a54f. * Remove `@Override` for `getMode` * Add Gradle 8.3 into test matrix * Compat `RelocationUtil#configureRelocation` for Groovy 3 and 4 * Log info
1 parent 85a0646 commit a0da04a

File tree

20 files changed

+66
-27
lines changed

20 files changed

+66
-27
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: [ ubuntu-latest, windows-latest ]
15-
# Always test on the latest version and all LTS.
16-
java: [ 11, 17, 21, 23 ]
15+
# Always test on the latest version and some LTS.
16+
java: [ 17, 21, 24 ]
17+
# Test on the minimum Gradle version and the latest.
18+
gradle: [ 8.3, current ]
19+
exclude:
20+
# Gradle 8.3 doesn't support Java 24.
21+
- gradle: 8.3
22+
java: 24
1723
runs-on: ${{ matrix.os }}
1824
steps:
1925
- uses: actions/checkout@v4
@@ -22,7 +28,7 @@ jobs:
2228
distribution: 'zulu'
2329
java-version: ${{ matrix.java }}
2430
- uses: gradle/actions/setup-gradle@v4
25-
- run: ./gradlew build
31+
- run: ./gradlew build --info "-PtestGradleVersion=${{ matrix.gradle }}"
2632

2733
publish-snapshot:
2834
needs: build

build.gradle.kts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ dependencies {
8484
implementation("org.apache.logging.log4j:log4j-core:2.24.1")
8585
implementation("org.vafer:jdependency:2.13")
8686

87-
testImplementation("org.spockframework:spock-core:2.3-groovy-3.0") {
87+
testImplementation("org.spockframework:spock-core:2.3-groovy-4.0") {
8888
exclude(group = "org.codehaus.groovy")
8989
exclude(group = "org.hamcrest")
9090
}
@@ -111,6 +111,12 @@ val isCI = providers.environmentVariable("CI").isPresent
111111
tasks.withType<Test>().configureEach {
112112
useJUnitPlatform()
113113

114+
val testGradleVersion = providers.gradleProperty("testGradleVersion").orNull.let {
115+
if (it == null || it == "current") GradleVersion.current().version else it
116+
}
117+
logger.info("Using test Gradle version: $testGradleVersion")
118+
systemProperty("TEST_GRADLE_VERSION", testGradleVersion)
119+
114120
maxParallelForks = Runtime.getRuntime().availableProcessors()
115121

116122
if (isCI) {

gradle/wrapper/gradle-wrapper.jar

1.83 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-rc-1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
#
4-
# Copyright © 2015-2021 the original authors.
4+
# Copyright © 2015 the original authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -114,7 +114,7 @@ case "$( uname )" in #(
114114
NONSTOP* ) nonstop=true ;;
115115
esac
116116

117-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
117+
CLASSPATH="\\\"\\\""
118118

119119

120120
# Determine the Java command to use to start the JVM.
@@ -205,15 +205,15 @@ fi
205205
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
206206

207207
# Collect all arguments for the java command:
208-
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
208+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
209209
# and any embedded shellness will be escaped.
210210
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
211211
# treated as '${Hostname}' itself on the command line.
212212

213213
set -- \
214214
"-Dorg.gradle.appname=$APP_BASE_NAME" \
215215
-classpath "$CLASSPATH" \
216-
org.gradle.wrapper.GradleWrapperMain \
216+
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
217217
"$@"
218218

219219
# Stop when "xargs" is not available.

gradlew.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ goto fail
7070
:execute
7171
@rem Setup the command line
7272

73-
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73+
set CLASSPATH=
7474

7575

7676
@rem Execute Gradle
77-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
77+
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
7878

7979
:end
8080
@rem End local scope for the variables with windows NT shell

src/docs/changes/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
## [Unreleased]
55

6+
**Fixed**
7+
8+
- Fix compatibility for Gradle 9.0.0 RC1. ([#1470](https://github.com/GradleUp/shadow/pull/1470))
9+
610

711
## [v8.3.6] (2025-02-02)
812

src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ShadowApplicationPlugin implements Plugin<Project> {
8484
startScripts.description = 'Creates OS specific scripts to run the project as a JVM application using the shadow jar'
8585
startScripts.group = ApplicationPlugin.APPLICATION_GROUP
8686
startScripts.classpath = project.files(jar)
87-
startScripts.conventionMapping.mainClassName = { javaApplication.mainClass.get() }
87+
startScripts.mainClass.set(javaApplication.mainClass)
8888
startScripts.conventionMapping.applicationName = { javaApplication.applicationName }
8989
startScripts.conventionMapping.outputDir = { new File(project.layout.buildDirectory.asFile.get(), 'scriptsShadow') }
9090
startScripts.conventionMapping.defaultJvmOpts = { javaApplication.applicationDefaultJvmArgs }

src/main/groovy/com/github/jengelman/gradle/plugins/shadow/impl/RelocatorRemapper.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.github.jengelman.gradle.plugins.shadow.relocation.RelocateClassContex
2424
import com.github.jengelman.gradle.plugins.shadow.relocation.RelocatePathContext
2525
import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator
2626
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowCopyAction.RelativeArchivePath
27+
import groovy.transform.CompileStatic
2728
import org.objectweb.asm.commons.Remapper
2829

2930
import java.util.regex.Matcher
@@ -34,6 +35,7 @@ import java.util.regex.Pattern
3435
*
3536
* @author John Engelman
3637
*/
38+
@CompileStatic
3739
class RelocatorRemapper extends Remapper {
3840

3941
private final Pattern classPattern = Pattern.compile("(\\[*)?L(.+)")

src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/DefaultZipCompressor.groovy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package com.github.jengelman.gradle.plugins.shadow.internal
1717

1818
import org.apache.tools.zip.Zip64Mode
1919
import org.apache.tools.zip.ZipOutputStream
20-
import org.gradle.api.UncheckedIOException
2120

2221
class DefaultZipCompressor implements ZipCompressor {
2322
private final int entryCompressionMethod

0 commit comments

Comments
 (0)