Skip to content

Conversation

aSemy
Copy link
Contributor

@aSemy aSemy commented Jul 28, 2024

Kotest is supposed to support Java 8, but there are a couple of places in the code that use Java utils that require 9+. This can be resolved by testing using a fixed Java Toolchain to always test using Java 8.

The JDK used to compile Kotest can also be fixed. Using newer JDKs is advantageous because of improved compilation performance and fixes. The Java compiler can be configured to emit classes compatible with Java 8 with the -release flag. (Kotlin has an analogous -Xjdk-release flag.)

To ensure compatibility going forward, I registered a new test run for launching the JVM tests with the maximum supported JDK. This will run automatically.

Using fixed Java Toolchains for compilation and running tests improves build performance, cacheability, and stability.

Usage

The Java versions used to compile, run, and test Kotest can be configured in libs.versions.toml

### Java compilation ###
# Kotest's minimum supported Java version
jvmMinTarget = "8"
# Kotest's maximum supported Java version (must be >= jvmMinTarget)
jvmMaxTarget = "21"
# JDK used to compile Kotest (must be >= jvmMaxTarget)
jvmCompiler = "21"

To test Java 8, run ./gradlew jvmTest. To test Java 21, run ./gradlew jvmMaxJdkTest.

Summary

  • Use Java toolchains to run and compile the build.
  • Add Foojay toolchain resolver, that will automatically download the required toolchains.
  • Use Java 21 to run Gradle and compile the code.
  • Set the minimum supported Java version to 8.
  • Set the maximum supported Java version to 21.
  • Create a new test task to run the tests with Java 21.
  • Fix code to support Java 8

@aSemy aSemy added the builds 🐘 PRs / Issues related to the CI/CD pipelines or Gradle builds label Jul 28, 2024
@aSemy aSemy force-pushed the adam/feat/java-toolchains branch from 1e773cc to f46b73d Compare July 28, 2024 10:35
- Use Java toolchains to run and compile the build.
- Add Foojay toolchain resolver, that will automatically download the required toolchains.
- Use Java 21 to run Gradle and compile the code.
- Set the minimum supported Java version to 8.
- Set the maximum supported Java version to 21.
- Create a new test task to run the tests with Java 21.
- Fix code to support Java 8.
@aSemy aSemy force-pushed the adam/feat/java-toolchains branch from 499a8fb to 11c9ff5 Compare July 28, 2024 11:53
@aSemy aSemy marked this pull request as ready for review July 28, 2024 13:56
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file are mostly tidying of the opt-in flags, but I also moved the JVM-specific compilation flags to kotest-jvm-conventions.gradle.kts

@sksamuel sksamuel added this pull request to the merge queue Jul 28, 2024
Merged via the queue into master with commit c4d9f27 Jul 29, 2024
7 checks passed
@sksamuel sksamuel deleted the adam/feat/java-toolchains branch July 29, 2024 00:38
github-merge-queue bot pushed a commit that referenced this pull request Aug 3, 2024
To maximise Gradle cache hits, and to use the best Gradle features, use
Java 21 to run Gradle builds.

Gradle has a new feature for running the Gradle Daemon with a fixed Java
version. This can be configured to run automatically. Currently Gradle
does not auto-provision the necessary Java version, but hopefully this
will be available in Gradle 8.10.

This PR should be merged after #4218, which will ensure that a stable
JDK is used for compilation and running tests.

---------

Co-authored-by: Sam <sam@sksamuel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builds 🐘 PRs / Issues related to the CI/CD pipelines or Gradle builds
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants