Skip to content

Commit eba7fa7

Browse files
committed
use toolchains to test against multiple JDKs
* build only on 17 * tests also on 21, 22, 23 * drop usage of github actions matrix
1 parent 614e380 commit eba7fa7

File tree

3 files changed

+63
-29
lines changed

3 files changed

+63
-29
lines changed

.github/workflows/gradle-build.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,29 @@ env:
1111

1212
jobs:
1313
gradle:
14-
strategy:
15-
matrix:
16-
java: [17, 21, 22, 23]
1714
runs-on: ubuntu-latest
1815
steps:
1916
- uses: actions/checkout@v4
2017

2118
- name: Setup Java
2219
uses: actions/setup-java@v4
2320
with:
24-
distribution: temurin
25-
java-version: ${{ matrix.java }}
21+
distribution: 'temurin'
22+
java-version: | # the last one is default
23+
23
24+
22
25+
21
26+
17
2627
cache: gradle
2728

2829
- name: Setup Gradle
2930
uses: gradle/actions/setup-gradle@v4
3031
with:
3132
add-job-summary-as-pr-comment: on-failure
3233

34+
- name: Gradle toolchains info
35+
run: ./gradlew -q javaToolchains
36+
3337
- name: Gradle build environment info
3438
run: ./gradlew -q buildEnvironment
3539

@@ -41,6 +45,8 @@ jobs:
4145
if: always() # always run even if the previous step fails
4246
with:
4347
name: junit-test-results
44-
path: '**/build/test-results/test/TEST-*.xml'
48+
path: |
49+
**/build/test-results/test/TEST-*.xml
50+
**/build/test-results/test-jdk*/TEST-*.xml
4551
retention-days: 1
4652
overwrite: true

.github/workflows/publish-test-results.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Download Test Report
16-
uses: dawidd6/action-download-artifact@6
16+
uses: dawidd6/action-download-artifact@9
1717
with:
1818
name: junit-test-results
1919
workflow: ${{ github.event.workflow.id }}

buildSrc/src/main/kotlin/framefork.java.gradle.kts

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ repositories {
2222
java {
2323
sourceCompatibility = JavaVersion.VERSION_17
2424
targetCompatibility = JavaVersion.VERSION_17
25+
26+
toolchain {
27+
languageVersion = JavaLanguageVersion.of(17)
28+
}
2529
}
2630

2731
kotlin {
@@ -63,28 +67,6 @@ idea {
6367
}
6468
}
6569

66-
tasks.withType<JavaCompile>() {
67-
doLast {
68-
javaCompiler.getOrNull()?.also {
69-
println("Used JDK: ${it.metadata.javaRuntimeVersion} ${it.metadata.vendor}")
70-
}
71-
}
72-
}
73-
74-
tasks.withType<Test> {
75-
useJUnitPlatform()
76-
77-
testlogger {
78-
showExceptions = true
79-
showStackTraces = true
80-
showFullStackTraces = true
81-
showCauses = true
82-
showPassedStandardStreams = false
83-
showSkippedStandardStreams = false
84-
showFailedStandardStreams = true
85-
}
86-
}
87-
8870
nullaway {
8971
annotatedPackages.add("org.framefork")
9072
}
@@ -181,6 +163,12 @@ tasks.withType<JavaCompile> {
181163
"com.github.rvesse.airline.annotations.Option"
182164
))
183165
}
166+
167+
doLast {
168+
javaCompiler.getOrNull()?.also {
169+
println("Used JDK: ${it.metadata.javaRuntimeVersion} ${it.metadata.vendor}")
170+
}
171+
}
184172
}
185173

186174
tasks.withType<Javadoc> {
@@ -189,7 +177,47 @@ tasks.withType<Javadoc> {
189177
}
190178

191179
tasks.named("test") {
180+
description = "Runs the unit tests against the default JDK"
181+
}
182+
183+
for (javaVersion in listOf(21, 22, 23)) {
184+
val testTask = tasks.register<Test>("test-jdk${javaVersion}") {
185+
group = "Verification"
186+
description = "Runs the unit tests against JDK $javaVersion"
187+
188+
javaLauncher.set(javaToolchains.launcherFor {
189+
languageVersion.set(JavaLanguageVersion.of(javaVersion))
190+
})
191+
192+
testClassesDirs = sourceSets.test.get().output.classesDirs
193+
classpath = sourceSets.test.get().runtimeClasspath
194+
}
195+
196+
tasks.named("check") {
197+
dependsOn(testTask)
198+
}
199+
}
200+
201+
tasks.withType<Test>() {
192202
outputs.upToDateWhen { false }
203+
204+
useJUnitPlatform()
205+
206+
testlogger {
207+
showExceptions = true
208+
showStackTraces = true
209+
showFullStackTraces = true
210+
showCauses = true
211+
showPassedStandardStreams = false
212+
showSkippedStandardStreams = false
213+
showFailedStandardStreams = true
214+
}
215+
216+
doFirst {
217+
javaLauncher.getOrNull()?.also {
218+
println("Using JDK: ${it.metadata.javaRuntimeVersion} ${it.metadata.vendor}")
219+
}
220+
}
193221
}
194222

195223
configurations.all {

0 commit comments

Comments
 (0)