Skip to content

Commit fe3e6e8

Browse files
committed
chore: use Gradle Java toolchains for the build and test execution
It enables decoupling of the build JVM vs test JVM. By default we use Java 17 for the build and target with --release 11. Then we vary Java version when running tests Signed-off-by: Vladimir Sitnikov <[email protected]>
1 parent 7c8030f commit fe3e6e8

31 files changed

+262
-97
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ jobs:
4242
- name: Set up JDK ${{ matrix.java-version }}
4343
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
4444
with:
45-
java-version: ${{ matrix.java-version }}
45+
# We need Java 17 for the build, so we install it always
46+
java-version: |
47+
${{ matrix.java-version }}
48+
17
4649
distribution: 'temurin'
4750
- name: Setup Go environment
4851
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
@@ -58,7 +61,7 @@ jobs:
5861

5962
# if you need to skip staging due to flakiness use "-PskipStaging"
6063
- name: Test sigstore-java
61-
run: ./gradlew build
64+
run: ./gradlew build -Porg.gradle.java.installations.auto-download=false -PjdkTestVersion=${{ matrix.java-version }}
6265

6366
- name: Ensure sigstore-java self signing still works
6467
if: ${{ !github.event.pull_request.head.repo.fork }}

.github/workflows/conformance.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
with:
2323
persist-credentials: false
2424

25-
- name: Set up JDK ${{ matrix.java-version }}
25+
- name: Set up JDK 17
2626
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
2727
with:
28-
java-version: ${{ matrix.java-version }}
28+
java-version: 17
2929
distribution: 'temurin'
3030

3131
- name: Setup Gradle
@@ -37,6 +37,12 @@ jobs:
3737
- name: Unpack sigstore-java distribution
3838
run: tar -xvf ${{ github.workspace }}/sigstore-cli/build/distributions/sigstore-cli-*.tar --strip-components 1
3939

40+
- name: Set up JDK ${{ matrix.java-version }}
41+
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
42+
with:
43+
java-version: ${{ matrix.java-version }}
44+
distribution: 'temurin'
45+
4046
- uses: sigstore/sigstore-conformance@640e7dfb715518eeeb492910c6d244cedcc6cfea # v0.0.17
4147
with:
4248
entrypoint: ${{ github.workspace }}/bin/sigstore-cli

.github/workflows/examples.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Setup Java
2929
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
3030
with:
31-
java-version: 11
31+
java-version: 17
3232
distribution: 'temurin'
3333

3434
- name: Setup Gradle

.github/workflows/release-sigstore-gradle-plugin-from-tag.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ jobs:
4747
with:
4848
persist-credentials: false
4949

50-
- name: Set up JDK 11
50+
- name: Set up JDK 17
5151
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
5252
with:
53-
java-version: 11
53+
java-version: 17
5454
distribution: 'temurin'
5555

5656
- name: Setup Gradle

.github/workflows/release-sigstore-java-from-tag.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ jobs:
4848
with:
4949
persist-credentials: false
5050

51-
- name: Set up JDK 11
51+
- name: Set up JDK 17
5252
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
5353
with:
54-
java-version: 11
54+
java-version: 17
5555
distribution: 'temurin'
5656

5757
- name: Setup Gradle

.github/workflows/tuf-conformance.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
with:
2323
persist-credentials: false
2424

25-
- name: Set up JDK ${{ matrix.java-version }}
25+
- name: Set up JDK 17
2626
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
2727
with:
28-
java-version: ${{ matrix.java-version }}
28+
java-version: 17
2929
distribution: 'temurin'
3030

3131
- name: Setup Gradle
@@ -37,6 +37,12 @@ jobs:
3737
- name: Unpack tuf distribution
3838
run: tar -xvf ${{ github.workspace }}/tuf-cli/build/distributions/tuf-cli-*.tar --strip-components 1
3939

40+
- name: Set up JDK ${{ matrix.java-version }}
41+
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
42+
with:
43+
java-version: ${{ matrix.java-version }}
44+
distribution: 'temurin'
45+
4046
- uses: theupdateframework/tuf-conformance@dee4e23533d7a12a6394d96b59b3ea0aa940f9bf # v2.2.0
4147
with:
4248
entrypoint: ${{ github.workspace }}/bin/tuf-cli

DEVELOPMENT.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
./gradlew build
44
```
55

6+
## execute tests with Java 23
7+
```sh
8+
./gradlew build -PjdkTestVersion=23
9+
```
10+
11+
# list build parameters
12+
13+
```sh
14+
./gradlew parameters
15+
```
16+
617
## skip tests that require OIDC logins
718

819
```sh
Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
1+
import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion
2+
13
plugins {
24
`kotlin-dsl`
35
}
46

57
group = "dev.sigstore.build-logic"
68

7-
java {
8-
sourceCompatibility = JavaVersion.VERSION_11
9-
targetCompatibility = JavaVersion.VERSION_11
10-
}
11-
12-
// We use precompiled script plugins (== plugins written as src/kotlin/build-logic.*.gradle.kts files,
13-
// and we need to declare dependency on org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin
14-
// to make it work.
15-
// Unfortunately, Gradle does not expose the version of `kotlin-dsl` in-core plugin, so we call `kotlin-dsl`
16-
// on our own PluginDependenciesSpec object, so it leaks the version to us.
17-
// See https://github.com/gradle/gradle/issues/17016
18-
val kotlinDslVersion = PluginDependenciesSpec { id ->
19-
object : PluginDependencySpec {
20-
var version: String? = null
21-
override fun version(version: String?) = apply { this.version = version }
22-
override fun apply(apply: Boolean) = this
23-
override fun toString() = version ?: ""
24-
}
25-
}.`kotlin-dsl`.toString()
26-
279
dependencies {
28-
implementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$kotlinDslVersion")
10+
// We use precompiled script plugins (== plugins written as src/kotlin/build-logic.*.gradle.kts files,
11+
// and we need to declare dependency on org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin
12+
// to make it work.
13+
// See https://github.com/gradle/gradle/issues/17016 regarding expectedKotlinDslPluginsVersion
14+
implementation("org.gradle.kotlin.kotlin-dsl:org.gradle.kotlin.kotlin-dsl.gradle.plugin:$expectedKotlinDslPluginsVersion")
2915
}
3016

31-
kotlinDslPluginOptions {
32-
jvmTarget.set("11")
33-
}
17+
// We need to figure out a version that is supported by the current JVM, and by the Kotlin Gradle plugin
18+
// So we settle on 21, 17, or 11 if the current JVM supports it
19+
listOf(21, 17, 11)
20+
.firstOrNull { JavaVersion.toVersion(it) <= JavaVersion.current() }
21+
?.let { buildScriptJvmTarget ->
22+
java {
23+
toolchain {
24+
languageVersion.set(JavaLanguageVersion.of(buildScriptJvmTarget))
25+
}
26+
}
27+
}

build-logic-commons/gradle-plugin/src/main/kotlin/build-logic.kotlin-dsl-gradle-plugin.gradle.kts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ plugins {
33
id("org.gradle.kotlin.kotlin-dsl") // this is 'kotlin-dsl' without version
44
}
55

6-
java {
7-
sourceCompatibility = JavaVersion.VERSION_11
8-
targetCompatibility = JavaVersion.VERSION_11
9-
}
10-
116
tasks.validatePlugins {
127
failOnWarning.set(true)
138
enableStricterValidation.set(true)
149
}
1510

16-
kotlinDslPluginOptions {
17-
jvmTarget.set("11")
18-
}
11+
// We need to figure out a version that is supported by the current JVM, and by the Kotlin Gradle plugin
12+
// So we settle on 21, 17, or 11 if the current JVM supports it
13+
listOf(21, 17, 11)
14+
.firstOrNull { JavaVersion.toVersion(it) <= JavaVersion.current() }
15+
?.let { buildScriptJvmTarget ->
16+
java {
17+
toolchain {
18+
languageVersion.set(JavaLanguageVersion.of(buildScriptJvmTarget))
19+
}
20+
}
21+
}

build-logic-commons/gradle-plugin/src/main/kotlin/buildlogic/DependencyHandlerScopeExtensions.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)