Skip to content

Commit f70a480

Browse files
bigdazclaude
andcommitted
Decouple build JDK from test JDK; upgrade shadow to 9.2.2
The CI matrix built the plugin fatjar and ran the TestKit tests with a single JDK per row, pinning the whole build toolchain to the oldest JDK under test (8). That blocked upgrading the shadow plugin, which now requires Java 17+. Split the two concerns: - The plugin fatjar is always built with a fixed, modern JDK (17). - The :plugin-test module compiles and runs on the JDK a given Gradle version requires, selected via a Gradle toolchain (-PtestJavaVersion). The matrix JDKs are already installed on the runner and exposed as JAVA_HOME_<version>_X64; org.gradle.java.installations.fromEnv points Gradle's toolchain detection at them (auto-detection does not scan the runner tool cache on its own). With the build no longer constrained to old JDKs, bump shadow 8.3.6 -> 9.2.2 (keeps the Gradle 8.14.4 wrapper; shadow 9.3+ would require Gradle 9). Shadow 9 exposes `configurations` as a SetProperty and provides native auto-relocation, so the manual per-package relocation loop is replaced with enableAutoRelocation + relocationPrefix, producing an equivalent relocated fatjar. Disable toolchain auto-download so a misconfigured testJavaVersion fails fast instead of silently provisioning a JDK. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a155642 commit f70a480

5 files changed

Lines changed: 48 additions & 26 deletions

File tree

.github/workflows/gradle.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Set up JDK
2121
uses: actions/setup-java@v5
2222
with:
23-
java-version: 11
23+
java-version: 17
2424
distribution: temurin
2525

2626
- name: Setup Gradle
@@ -35,7 +35,10 @@ jobs:
3535
needs: quick-check
3636
strategy:
3737
fail-fast: false
38-
# Test earliest and latest supported version of 5.x, 6.x, 7.x, and 8.x
38+
# Test earliest and latest supported version of 5.x, 6.x, 7.x, and 8.x.
39+
# The plugin fatjar is always built with a fixed, modern JDK (see "Set up JDK" below);
40+
# java-version here is only the JDK that each Gradle version under test runs on, selected
41+
# via a Gradle toolchain (-PtestJavaVersion). Older Gradle versions require older JDKs.
3942
matrix:
4043
include:
4144
- gradle-version: "5.2.1"
@@ -62,19 +65,30 @@ jobs:
6265
steps:
6366
- uses: actions/checkout@v6
6467

68+
# Fixed build JDK: compiles the plugin and builds the shadow fatjar. Must satisfy the build
69+
# tooling's own JDK requirement (the shadow plugin needs Java 17+), independent of the older
70+
# JDK the Gradle version under test runs on.
6571
- name: Set up JDK
6672
uses: actions/setup-java@v5
6773
with:
68-
java-version: ${{ matrix.java-version }}
74+
java-version: 17
6975
distribution: temurin
7076

7177
- name: Setup Gradle
7278
uses: gradle/actions/setup-gradle@v6
7379
with:
7480
develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
7581

82+
# -PtestJavaVersion runs the :plugin-test module (and thus the Gradle version under test) on
83+
# the matrix JDK via a Gradle toolchain. That JDK is already installed on the runner and
84+
# exposed as JAVA_HOME_<version>_X64; org.gradle.java.installations.fromEnv points Gradle's
85+
# toolchain detection at it (auto-detection does not scan the runner tool cache on its own).
7686
- name: Execute Gradle Build
77-
run: ./gradlew -S build -DtestGradleVersion=${{ matrix.gradle-version }}
87+
run: >
88+
./gradlew -S build
89+
-DtestGradleVersion=${{ matrix.gradle-version }}
90+
-PtestJavaVersion=${{ matrix.java-version }}
91+
-Dorg.gradle.java.installations.fromEnv=JAVA_HOME_${{ matrix.java-version }}_X64
7892
7993
# Aggregates the test-gradle-version matrix into a single status check.
8094
# Enable "merge when checks pass" / branch protection against this job rather than
@@ -101,7 +115,7 @@ jobs:
101115
- name: Set up JDK
102116
uses: actions/setup-java@v5
103117
with:
104-
java-version: 11
118+
java-version: 17
105119
distribution: temurin
106120

107121
- name: Setup Gradle

gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@ org.gradle.jvmargs=-Xmx5000m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemor
22
org.gradle.caching=true
33
org.gradle.configuration-cache=true
44

5+
# Never auto-provision JDKs for toolchains: the required JDKs are expected to be already installed
6+
# (auto-detected locally, exposed via org.gradle.java.installations.fromEnv on CI). Downloading would
7+
# mask a misconfigured -PtestJavaVersion instead of failing fast.
8+
org.gradle.java.installations.auto-download=false
9+
510
systemProp.gradle.publish.skip.namespace.check=true

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ jetbrains-annotations = { group = "org.jetbrains", name = "annotations", version
2525
google-gson = { group = "com.google.code.gson", name = "gson", version = "2.13.2" }
2626

2727
[plugins]
28-
shadow-jar = { id = "com.gradleup.shadow", version = "8.3.6"}
28+
shadow-jar = { id = "com.gradleup.shadow", version = "9.2.2"}
2929
plugin-publish = { id = "com.gradle.plugin-publish", version = "2.1.0" }

plugin-test/build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ sourceSets.test {
3838
resources.srcDir(writeTestConfig.map { it.generatedResourceDirectory })
3939
}
4040

41+
// Compile and run this module (and thus the Gradle version under test) on a specific JDK with
42+
// -PtestJavaVersion=8, decoupled from the JDK used to build the :plugin fatjar. This lets the
43+
// plugin be built with a fixed, modern JDK (as required by newer build tooling such as the
44+
// shadow plugin) while still exercising older Gradle versions on the older JDKs they require.
45+
// Test classes must be *compiled* for the test JDK too, not just executed on it, so we set a
46+
// project-wide toolchain rather than only the test task's launcher. When unset, the module uses
47+
// the JDK that is building the project.
48+
val testJavaVersion = providers.gradleProperty("testJavaVersion")
49+
.map { JavaLanguageVersion.of(it.toInt()) }
50+
51+
if (testJavaVersion.isPresent) {
52+
java {
53+
toolchain {
54+
languageVersion = testJavaVersion.get()
55+
}
56+
}
57+
}
58+
4159
tasks.withType<Test>().configureEach {
4260
// Use JUnit Platform for unit tests.
4361
useJUnitPlatform()

plugin/build.gradle.kts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import com.gradle.publish.PublishTask
33
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
44
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
55
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
6-
import java.util.jar.JarFile
76

87
// Upgrade transitive dependencies in plugin classpath
98
buildscript {
@@ -92,25 +91,11 @@ val shadowJarTask = tasks.named<ShadowJar>("shadowJar") {
9291
// Gradle versions. See https://github.com/gradle/gradle/issues/24390
9392
exclude("META-INF/versions/**")
9493
configurations = listOf(shadowImplementation)
95-
val projectGroup = project.group
96-
doFirst {
97-
configurations.forEach { configuration ->
98-
configuration.files.forEach { jar ->
99-
JarFile(jar).use { jf ->
100-
jf.entries().iterator().forEach { entry ->
101-
if (entry.name.endsWith(".class") && entry.name != "module-info.class") {
102-
val packageName =
103-
entry
104-
.name
105-
.substring(0..entry.name.lastIndexOf('/'))
106-
.replace('/', '.')
107-
relocate(packageName, "${projectGroup}.shadow.$packageName")
108-
}
109-
}
110-
}
111-
}
112-
}
113-
}
94+
// Relocate every bundled package under `<group>.shadow.` so the plugin's own dependencies can
95+
// never clash with those of the build it is applied to. shadow 9.x does this natively via
96+
// auto-relocation, replacing the manual per-package relocation loop we maintained previously.
97+
enableAutoRelocation = true
98+
relocationPrefix = "${project.group}.shadow"
11499
}
115100

116101
configurations.archives.get().artifacts.clear()

0 commit comments

Comments
 (0)