Skip to content

Commit eb7407a

Browse files
committed
update build to work with gradle 9.1 and Java 25
create separate test tasks for each java version attempt to recreate project isolation failure create separate Gradle test task for each JVM version. these are still individually invoked by github actions matrix
1 parent 2a10370 commit eb7407a

File tree

16 files changed

+175
-142
lines changed

16 files changed

+175
-142
lines changed

.github/workflows/build-and-check.yml

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
run: echo "The selected java versions are ${{ steps.set-matrix.outputs.version_matrix }}"
2626
outputs:
2727
version_matrix: ${{ steps.set-matrix.outputs.version_matrix }}
28-
build:
28+
test-jvm:
2929
needs: build-jvm-matrix
3030
strategy:
3131
fail-fast: false
@@ -49,7 +49,9 @@ jobs:
4949
- name: set up JDK
5050
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
5151
with:
52-
java-version: ${{ matrix.java_version }}
52+
java-version: |
53+
${{ matrix.java_version }}
54+
21
5355
distribution: 'zulu'
5456
- name: Setup Gradle
5557
uses: gradle/actions/setup-gradle@ed408507eac070d1f99cc633dbcf757c94c7933a # v4.4.3
@@ -66,7 +68,7 @@ jobs:
6668
${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradlew') }}-
6769
${{ runner.os }}-gradle-wrapper-
6870
- name: Test Plugin
69-
run: ./plugin/gradlew -p ./plugin check --no-daemon
71+
run: ./plugin/gradlew -p ./plugin test${{ matrix.java_version }} --no-daemon
7072
- name: Upload test results
7173
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
7274
if: failure()
@@ -83,6 +85,45 @@ jobs:
8385
replay_pid*
8486
plugin/hs_err_pid*
8587
plugin/replay_pid*
88+
89+
build:
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: Harden the runner (Audit all outbound calls)
93+
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
94+
with:
95+
egress-policy: audit
96+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
97+
- name: set up JDK
98+
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
99+
with:
100+
java-version: 21
101+
cache: 'gradle'
102+
distribution: 'zulu'
103+
- name: Setup Gradle
104+
uses: gradle/actions/setup-gradle@ed408507eac070d1f99cc633dbcf757c94c7933a # v4.4.3
105+
with:
106+
cache-overwrite-existing: true
107+
- name: Restore TestKit cache
108+
# Inspired by https://github.com/actions/cache/issues/432#issuecomment-740376179
109+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
110+
with:
111+
path: |
112+
plugin/.gradle-test-kit/caches/modules-2
113+
plugin/.gradle-test-kit/caches/files-2.1
114+
plugin/.gradle-test-kit/caches/metadata-2.96
115+
key: gradle-wrapper-${{ hashFiles('**/gradlew') }}-${{ github.sha }}
116+
restore-keys: |
117+
gradle-wrapper-${{ hashFiles('**/gradlew') }}-
118+
gradle-wrapper-
119+
- name: Check Plugin
120+
run: ./plugin/gradlew -p ./plugin check --no-daemon
121+
- name: Upload test results
122+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
123+
if: failure()
124+
with:
125+
name: test-results
126+
path: plugin/build/reports/tests/test/
86127
- name: Check plugin codestyle
87128
run: ./plugin/gradlew -p ./plugin ktlintCheck --no-daemon
88129

@@ -124,10 +165,10 @@ jobs:
124165
with:
125166
egress-policy: audit
126167
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
127-
- name: set up JDK 11
168+
- name: set up JDK 21
128169
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
129170
with:
130-
java-version: 11
171+
java-version: 21
131172
distribution: 'zulu'
132173
- name: Setup Gradle
133174
uses: gradle/actions/setup-gradle@ed408507eac070d1f99cc633dbcf757c94c7933a # v4.4.3

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
- Update build to work with gradle 9.1 and Java 25 [#962](https://github.com/JLLeitschuh/ktlint-gradle/pull/962)
1011
- Collapse sourcesets to simply build [#964](https://github.com/JLLeitschuh/ktlint-gradle/pull/964)
1112

1213
## [13.1.0] - 2025-08-21
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
toolchainVersion=21

gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionSha256Sum=20f1b1176237254a6fc204d8434196fa11a4cfb387567519c61556e8710aed78
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
3+
distributionSha256Sum=a17ddd85a26b6a7f5ddb71ff8b05fc5104c0202c6e64782429790c933686c806
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
55
networkTimeout=10000
66
validateDistributionUrl=true
77
zipStoreBase=GRADLE_USER_HOME

plugin/build.gradle.kts

Lines changed: 76 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask
2-
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
32
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
43
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
54
import org.gradle.api.tasks.testing.logging.TestLogEvent
65
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
6+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
77
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
88
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
99
import org.jetbrains.kotlin.util.prefixIfNot
@@ -13,7 +13,7 @@ plugins {
1313
`kotlin-dsl`
1414
`maven-publish`
1515
id("org.jlleitschuh.gradle.ktlint")
16-
id("com.github.johnrengelman.shadow")
16+
id("com.gradleup.shadow")
1717
id("com.github.breadmoirai.github-release")
1818
id("com.netflix.nebula.release")
1919
}
@@ -27,6 +27,8 @@ repositories {
2727
}
2828

2929
java {
30+
withJavadocJar()
31+
withSourcesJar()
3032
toolchain {
3133
languageVersion.set(JavaLanguageVersion.of(8))
3234
}
@@ -38,30 +40,12 @@ ktlint {
3840

3941
tasks.withType<KotlinCompile> {
4042
compilerOptions {
41-
languageVersion.set(KotlinVersion.KOTLIN_1_7)
42-
apiVersion.set(KotlinVersion.KOTLIN_1_7)
43+
languageVersion.set(KotlinVersion.KOTLIN_1_8)
44+
apiVersion.set(KotlinVersion.KOTLIN_1_8)
4345
jvmTarget.set(JvmTarget.JVM_1_8)
4446
}
4547
}
4648

47-
tasks.withType<PluginUnderTestMetadata>().configureEach {
48-
pluginClasspath.from(configurations.compileOnly)
49-
}
50-
51-
/**
52-
* Special configuration to be included in resulting shadowed jar, but not added to the generated pom and gradle
53-
* metadata files.
54-
*/
55-
val shadowImplementation by configurations.creating
56-
configurations {
57-
val compileOnly by getting {
58-
extendsFrom(shadowImplementation)
59-
isCanBeResolved = true
60-
}
61-
}
62-
configurations["compileOnly"].extendsFrom(shadowImplementation)
63-
configurations["testImplementation"].extendsFrom(shadowImplementation)
64-
6549
dependencies {
6650
compileOnly("com.pinterest.ktlint:ktlint-cli-reporter-core:1.0.0")
6751
compileOnly("com.pinterest.ktlint:ktlint-rule-engine:1.0.0")
@@ -70,23 +54,70 @@ dependencies {
7054
compileOnly(libs.kotlin.gradle.plugin)
7155
compileOnly(libs.android.gradle.plugin)
7256
compileOnly(kotlin("stdlib-jdk8"))
57+
implementation(libs.semver)
58+
implementation(libs.jgit)
59+
implementation(libs.commons.io)
7360

74-
shadowImplementation(libs.semver)
75-
shadowImplementation(libs.jgit)
76-
shadowImplementation(libs.commons.io)
77-
// Explicitly added for shadow plugin to relocate implementation as well
78-
shadowImplementation(libs.slf4j.nop)
79-
80-
testImplementation(libs.junit.jupiter)
8161
testImplementation(libs.assertj.core)
8262
testImplementation(libs.kotlin.reflect)
8363
testImplementation(libs.ktlint.rule.engine)
8464
testImplementation(libs.archunit.junit5)
8565
}
8666

67+
fun JvmTestSuite.extendFromTest() {
68+
sources {
69+
java {
70+
source(project.sourceSets.named("test").map { it.java }.get())
71+
}
72+
kotlin {
73+
source(project.sourceSets.named("test").map { it.kotlin }.get())
74+
}
75+
resources {
76+
source(project.sourceSets.named("test").map { it.resources }.get())
77+
}
78+
compileClasspath += project.sourceSets["test"].compileClasspath + project.sourceSets["main"].compileClasspath
79+
runtimeClasspath += project.sourceSets["test"].runtimeClasspath + project.sourceSets["main"].runtimeClasspath
80+
81+
// make internal classes available to tests
82+
val compilations = project
83+
.extensions
84+
.getByType(KotlinJvmProjectExtension::class.java).target.compilations
85+
compilations.getByName(sources.name)
86+
.associateWith(compilations.getByName(SourceSet.MAIN_SOURCE_SET_NAME))
87+
}
88+
}
89+
90+
fun getCurrentJavaVersion(): String {
91+
return Runtime::class.java.getPackage().specificationVersion // java 8
92+
?: Runtime::class.java.getMethod("version").invoke(null).toString() // java 9+
93+
}
94+
testing {
95+
suites {
96+
named<JvmTestSuite>("test") {
97+
useJUnitJupiter()
98+
}
99+
listOf(8, 11, 17, 21, 25) // TODO get from data feed
100+
.forEach {
101+
register<JvmTestSuite>("test$it") {
102+
extendFromTest()
103+
targets.all {
104+
dependencies {
105+
implementation(gradleTestKit())
106+
}
107+
testTask.configure {
108+
javaLauncher.set(
109+
javaToolchains.launcherFor {
110+
languageVersion.set(JavaLanguageVersion.of(JavaVersion.current().majorVersion))
111+
}
112+
)
113+
}
114+
}
115+
}
116+
}
117+
}
118+
}
87119
tasks.withType<Test> {
88120
dependsOn("publishToMavenLocal")
89-
useJUnitPlatform()
90121
maxParallelForks = 6 // no point in this being higher than the number of gradle workers
91122

92123
// Set the system property for the project version to be used in the tests
@@ -110,15 +141,8 @@ tasks.withType<Test> {
110141
maxFailures.set(10)
111142
}
112143
}
113-
114-
javaLauncher.set(
115-
javaToolchains.launcherFor {
116-
languageVersion.set(JavaLanguageVersion.of(JavaVersion.current().majorVersion))
117-
}
118-
)
119144
}
120145

121-
val relocateShadowJar = tasks.register<ConfigureShadowRelocation>("relocateShadowJar")
122146
val shadowJarTask = tasks.named<ShadowJar>("shadowJar") {
123147
manifest {
124148
attributes(
@@ -128,16 +152,12 @@ val shadowJarTask = tasks.named<ShadowJar>("shadowJar") {
128152
"Implementation-Vendor-Id" to project.group
129153
)
130154
}
131-
// Enable package relocation in resulting shadow jar
132-
relocateShadowJar.get().apply {
133-
prefix = "$pluginGroup.shadow"
134-
target = this@named
135-
}
136-
137-
dependsOn(relocateShadowJar)
138-
minimize()
139-
archiveClassifier.set("")
140-
configurations = listOf(shadowImplementation)
155+
relocate("com.googlecode.javaewah", "$pluginGroup.shadow.com.googlecode.javaewah")
156+
relocate("net.swiftzer", "$pluginGroup.shadow.net.swiftzer")
157+
relocate("org.apache.commons.io", "$pluginGroup.shadow.org.apache.commons.io")
158+
relocate("org.eclipse.jgit", "$pluginGroup.shadow.org.eclipse.jgit")
159+
relocate("org.slf4j", "$pluginGroup.shadow.org.slf4j")
160+
archiveClassifier.set(null)
141161
}
142162

143163
// Add shadow jar to the Gradle module metadata api and runtime configurations
@@ -150,7 +170,7 @@ configurations {
150170

151171
tasks.whenTaskAdded {
152172
if (name == "publishPluginJar" || name == "generateMetadataFileForPluginMavenPublication") {
153-
dependsOn(tasks.named("shadowJar"))
173+
dependsOn(tasks.named("jar"))
154174
}
155175
}
156176

@@ -162,11 +182,11 @@ tasks.named("jar").configure {
162182
val ensureDependenciesAreInlined by tasks.registering {
163183
description = "Ensures all declared dependencies are inlined into shadowed jar"
164184
group = HelpTasksPlugin.HELP_GROUP
165-
dependsOn(tasks.shadowJar)
185+
dependsOn(tasks.named<Jar>("shadowJar"))
166186

167187
doLast {
168188
val nonInlinedDependencies = mutableListOf<String>()
169-
zipTree(tasks.shadowJar.flatMap { it.archiveFile }).visit {
189+
zipTree(tasks.named<Jar>("shadowJar").flatMap { it.archiveFile }).visit {
170190
if (!isDirectory) {
171191
val path = relativePath
172192
if (!path.startsWith("META-INF") &&
@@ -234,18 +254,22 @@ fun setupPublishingEnvironment() {
234254

235255
setupPublishingEnvironment()
236256

237-
configurations.named("implementation") {
257+
configurations.named("runtimeClasspath") {
238258
attributes {
239259
attribute(GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named("7.4"))
240260
}
241261
}
242262

243263
gradlePlugin {
264+
vcsUrl = "https://github.com/JLLeitschuh/ktlint-gradle"
265+
website = vcsUrl
266+
description = "Provides a convenient wrapper plugin over the ktlint project."
244267
(plugins) {
245268
register("ktlintPlugin") {
246269
id = "org.jlleitschuh.gradle.ktlint"
247270
implementationClass = "org.jlleitschuh.gradle.ktlint.KtlintPlugin"
248271
displayName = "Ktlint Gradle Plugin"
272+
tags = listOf("ktlint", "kotlin", "linting")
249273
}
250274
}
251275
}
@@ -254,46 +278,12 @@ tasks.named<ValidatePlugins>("validatePlugins").configure {
254278
enableStricterValidation = true
255279
}
256280

257-
// Need to move publishing configuration into afterEvaluate {}
258-
// to override changes done by "com.gradle.plugin-publish" plugin in afterEvaluate {} block
259-
// See PublishPlugin class for details
260-
afterEvaluate {
261-
publishing {
262-
publications {
263-
withType<MavenPublication> {
264-
// Special workaround to publish shadow jar instead of normal one. Name to override peeked here:
265-
// https://github.com/gradle/gradle/blob/master/subprojects/plugin-development/src/main/java/org/gradle/plugin/devel/plugins/MavenPluginPublishPlugin.java#L73
266-
if (name == "pluginMaven") {
267-
setArtifacts(
268-
listOf(
269-
shadowJarTask.get()
270-
)
271-
)
272-
}
273-
}
274-
}
275-
}
276-
}
277-
278-
pluginBundle {
279-
vcsUrl = "https://github.com/JLLeitschuh/ktlint-gradle"
280-
website = vcsUrl
281-
description = "Provides a convenient wrapper plugin over the ktlint project."
282-
tags = listOf("ktlint", "kotlin", "linting")
283-
284-
(plugins) {
285-
"ktlintPlugin" {
286-
displayName = "Ktlint Gradle Plugin"
287-
}
288-
}
289-
}
290-
291281
githubRelease {
292282
setToken(providers.systemProperty("github.secret"))
293283
owner = "JLLeitschuh"
294284
repo = "ktlint-gradle"
295285
overwrite = true
296-
releaseAssets(tasks.named("shadowJar"))
286+
releaseAssets(tasks.named("jar"))
297287

298288
fun isPreReleaseVersion(): Boolean {
299289
val version = project.version.toString()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
toolchainVersion=21

0 commit comments

Comments
 (0)