Skip to content

Commit

Permalink
Bump JDK running Gradle from 11 to 17
Browse files Browse the repository at this point in the history
This commit decouples the JDK running Gradle from the one building the
project.

Gradle will by default use the same JDK for building the project as it
does for running Gradle. Newer JDKs are assumed to be more performant,
contain fewer bugs and to come with desirable features that we would
like to utilize in our build, but doing so should not endanger
backwards compatibility for the plugin itself. We can do that now by
utilizing Gradle toolchains, which allows us to use one JDK/JRE for
running Gradle and the other for building the project, i.e. executing
`javac`.

Doing this requires us to make multiple JDKs available to the Gradle
build action for each individual execution of the build. The setup-java
action doesn't support this at the moment, and the multiple build steps
configured for actions/setup-java in this commit is at best a
workaround for this, and at worst a bad assumption with respect to
environment variables or other settings being overwritten. Furthermore,
there's no handling of duplicate invocations of the action.

Hopefully both actions/setup-java and gradle/gradle-build-action will
handle all of this gracefully.

For more details, see:
- actions/setup-java#44
- gradle/gradle#14903
  • Loading branch information
rognan committed Nov 28, 2021
1 parent 0cb2b7d commit 665acd0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
35 changes: 26 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,47 @@ jobs:
strategy:
matrix:
include:
- { os: 'macos-latest', arch: 'x64', java-version: '11', gradle-version: '7.3' }
- { os: 'ubuntu-latest', arch: 'x64', java-version: '11', gradle-version: '7.3' }
- { os: 'windows-latest', arch: 'x64', java-version: '11', gradle-version: '7.3' }
name: Gradle ${{ matrix.gradle-version }}, Java ${{ matrix.java-version }} on ${{ matrix.os }} (${{ matrix.arch }})
# Gradle is run with `gradle-jdk` and builds with `build-jdk` by utilizing Gradle toolchain support
- { os: 'macos-latest', arch: 'x64', build-jdk: '11', gradle-jdk: '17', gradle-version: '7.3' }
- { os: 'ubuntu-latest', arch: 'x64', build-jdk: '11', gradle-jdk: '17', gradle-version: '7.3' }
- { os: 'windows-latest', arch: 'x64', build-jdk: '11', gradle-jdk: '17', gradle-version: '7.3' }
name: >
Gradle ${{ matrix.gradle-version }} on ${{ matrix.os }} (${{ matrix.arch }})
w/JDK ${{ matrix.gradle-jdk }} building w/JDK ${{ matrix.build-jdk}}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Configure JDK ${{ matrix.java-version }} (${{ matrix.arch }})
- name: Configure Gradle JDK ${{ matrix.gradle-jdk }} (${{ matrix.arch }})
id: configure-gradle-jdk
uses: actions/setup-java@v2
with:
architecture: ${{ matrix.arch }}
distribution: 'temurin'
java-version: ${{ matrix.java-version }}
- uses: gradle/gradle-build-action@v2
java-version: ${{ matrix.gradle-jdk }}
- name: Configure Build JDK ${{ matrix.build-jdk }} (${{ matrix.arch }})
id: configure-build-jdk
uses: actions/setup-java@v2
with:
architecture: ${{ matrix.arch }}
distribution: 'temurin'
java-version: ${{ matrix.build-jdk }}
- name: >
Build w/Gradle ${{ matrix.gradle-version }} on JDK ${{ matrix.gradle-jdk }}
w/JDK ${{ matrix.build-jdk }}
uses: gradle/gradle-build-action@v2
with:
# Only write to the cache on the 'main' branch
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
gradle-version: ${{ matrix.gradle-version }}
arguments: build --scan
arguments: >
build --scan
-Porg.gradle.java.installations.auto-download=false
-Porg.gradle.java.installations.paths=${{ steps.configure-gradle-jdk.outputs.path }},${{ steps.configure-build-jdk.outputs.path }}
- name: Upload build reports
uses: actions/upload-artifact@v2
if: always()
with:
name: build-reports-${{ matrix.os }}-${{ matrix.arch }}-jdk-${{ matrix.java-version }}
name: build-reports-${{ matrix.os }}-${{ matrix.arch }}-jdk-${{ matrix.gradle-jdk }}
path: |
build/reports
./**/build/reports
13 changes: 13 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
id("org.jlleitschuh.gradle.ktlint") version "10.2.0"
}

val jdkVersion: JavaLanguageVersion = JavaLanguageVersion.of(11)
val functionalTestSourceSet: SourceSet = sourceSets.create("functionalTest")
configurations["functionalTestImplementation"].extendsFrom(configurations["testImplementation"])

Expand All @@ -30,6 +31,18 @@ gradlePlugin {
}
}

java {
toolchain {
languageVersion.set(jdkVersion)
}
}

kotlin {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(jdkVersion)
}
}

tasks.withType<JavaCompile>().configureEach {
options.release.set(8)
}
Expand Down

0 comments on commit 665acd0

Please sign in to comment.