From 57d4541aa9014e489f2c66ec9d68540c3b55294c Mon Sep 17 00:00:00 2001 From: Mariano Barrios Date: Wed, 1 Nov 2023 13:22:10 +0100 Subject: [PATCH] Build for Java 21 --- .github/workflows/main.yml | 10 +++++--- build.gradle | 29 +++++++++++++++-------- src/test/scala/tlschannel/TestLogger.java | 14 +++++++++++ 3 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 src/test/scala/tlschannel/TestLogger.java diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ae58a1ae..c1402b10 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,11 +8,15 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java-version: [ 8, 11, 17, 20 ] + java-version: [ 8, 11, 17, 21 ] steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: ${{ matrix.java-version }} - - run: ./gradlew assemble check --info \ No newline at end of file + java-version: | + ${{ matrix.java-version }} + 21 + - run: ./gradlew assemble check --info + env: + JAVA_TOOLCHAIN: ${{ matrix.java-version }} \ No newline at end of file diff --git a/build.gradle b/build.gradle index ce4b945a..b8052825 100644 --- a/build.gradle +++ b/build.gradle @@ -3,10 +3,18 @@ plugins { id 'scala' id 'signing' id 'maven-publish' - // pinned version due to Java 8 compatibility - id "com.diffplug.spotless" version "6.11.0" - // pinned version due to https://github.com/spotbugs/spotbugs/issues/2041 - id "com.github.spotbugs" version "5.0.13" + id "com.diffplug.spotless" version "6.22.0" + id "com.github.spotbugs" version "5.2.1" +} + +var javaToolchain = System.getenv('JAVA_TOOLCHAIN') + +java { + if (javaToolchain != null) { + toolchain { + languageVersion = JavaLanguageVersion.of(javaToolchain) + } + } } compileJava { @@ -39,7 +47,8 @@ dependencies { spotless { java { - palantirJavaFormat() + // remove when spotless moved to this Palantir version + palantirJavaFormat("2.38.0") } scala { scalafmt('3.7.1').configFile('.scalafmt.conf') @@ -48,10 +57,10 @@ spotless { // There are some compatibility issues with spotless older Java versions, // but we don't need to cross-do style checks anyway -if (JavaVersion.current().ordinal() < JavaVersion.VERSION_17.ordinal()) { - tasks.findByName("spotlessScala").enabled(false) - tasks.findByName("spotlessJava").enabled(false) -} +// if (JavaVersion.current().ordinal() < JavaVersion.VERSION_17.ordinal()) { +// tasks.findByName("spotlessScala").enabled(false) +// tasks.findByName("spotlessJava").enabled(false) +// } spotbugs { ignoreFailures = false @@ -113,7 +122,7 @@ task allocationTest(type: JavaExec) { jvmArgs = ['-XX:+UnlockExperimentalVMOptions', '-XX:+UseEpsilonGC'] } -if (JavaVersion.current().ordinal() >= JavaVersion.VERSION_11.ordinal()) { +if (javaToolchain == null || javaToolchain != "8") { check.dependsOn allocationTest } diff --git a/src/test/scala/tlschannel/TestLogger.java b/src/test/scala/tlschannel/TestLogger.java new file mode 100644 index 00000000..e6723fb0 --- /dev/null +++ b/src/test/scala/tlschannel/TestLogger.java @@ -0,0 +1,14 @@ +package tlschannel; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; + +@TestInstance(Lifecycle.PER_CLASS) +public class TestLogger { + + @Test + public void logJdk() { + System.out.println("java.version: " + System.getProperty("java.version")); + } +}