diff --git a/.github/actions/setup-build/action.yml b/.github/actions/setup-build/action.yml new file mode 100644 index 000000000..8ab3f8256 --- /dev/null +++ b/.github/actions/setup-build/action.yml @@ -0,0 +1,68 @@ +name: 'Setup Build Environment' +description: 'Sets up JDK(s), Maven Develocity, and optionally SoftHSM' +inputs: + java-version-tests: + description: 'The primary/test Java version' + required: false + default: '17' + distribution: + description: 'JDK distribution to use' + required: false + default: 'zulu' + java-version-maven: + description: 'The Java version used to execute Maven' + required: false + default: '17' + develocity-access-key: + description: 'Develocity access key' + required: false + setup-softhsm: + description: 'Whether to set up SoftHSM' + required: false + default: 'true' + +runs: + using: 'composite' + steps: + + - name: Set up JDK ${{ inputs.java-version-tests }} (Runs Tests) + if: ${{ inputs.java-version != inputs.java-version-maven }} + uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 + with: + distribution: ${{ inputs.distribution }} + java-version: ${{ inputs.java-version-tests }} + cache: 'maven' + check-latest: true + + - name: Set up JDK ${{ inputs.java-version-maven }} (Runs Maven) + uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 + with: + distribution: ${{ inputs.distribution }} + java-version: ${{ inputs.java-version-maven }} + cache: 'maven' + check-latest: true + + - name: Set up OSS Community Develocity Instance for Maven + uses: gradle/develocity-actions/setup-maven@974e8dbcbda40db6828fc35f349c80a7c0e71529 #v2.1 + with: + develocity-access-key: ${{ inputs.develocity-access-key }} + + - name: Install softhsm2 + if: ${{ inputs.setup-softhsm == 'true' }} + run: sudo apt-get install -y softhsm2 + shell: bash + + - name: Install opensc + if: ${{ inputs.setup-softhsm == 'true' }} + run: sudo apt-get install -y opensc + shell: bash + + - name: Ensure SoftHSM user configuration + if: ${{ inputs.setup-softhsm == 'true' }} + run: impl/src/test/scripts/softhsm configure + shell: bash + + - name: Populate SoftHSM with JJWT test keys + if: ${{ inputs.setup-softhsm == 'true' }} + run: impl/src/test/scripts/softhsm import + shell: bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b607a342f..b144899ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: CI on: - workflow_dispatch: + workflow_dispatch: pull_request: # all pull requests push: branches: @@ -11,151 +11,60 @@ env: MVN_CMD: ./mvnw --no-transfer-progress -B jobs: - oracle: - strategy: - matrix: - java: [ '17' ] + build: runs-on: 'ubuntu-latest' - name: jdk-${{ matrix.java }}-oracle - steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4.7.0 - with: - distribution: oracle - java-version: ${{ matrix.java }} - - name: Set up OSS Community Develocity Instance for Maven - uses: gradle/develocity-actions/setup-maven@v2.1 - with: - develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} - - name: Install softhsm2 - run: sudo apt-get install -y softhsm2 - - name: Install opensc - run: sudo apt-get install -y opensc - - name: Ensure SoftHSM user configuration - run: impl/src/test/scripts/softhsm configure - - name: Populate SoftHSM with JJWT test keys - run: impl/src/test/scripts/softhsm import - - name: Build - # run a full build, just as we would for a release (i.e. the `ossrh` profile), but don't use gpg - # to sign artifacts, since we don't want to mess with storing signing credentials in CI: - run: ${{env.MVN_CMD}} verify -Possrh -Dgpg.skip=true - - temurin: strategy: + fail-fast: false matrix: - java: [ '8', '11', '17', '18' ] - runs-on: 'ubuntu-latest' - name: jdk-${{ matrix.java }}-temurin + distribution: [ 'oracle', 'temurin', 'zulu', 'corretto', 'semeru' ] + java-version: [ 8, 11, 17, 21, 25 ] + # Oracle only provides JDK 17+, so exclude earlier versions: + exclude: + - distribution: 'oracle' + java-version: 8 + - distribution: 'oracle' + java-version: 11 + name: jdk-${{ matrix.java-version }}-${{ matrix.distribution }} steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 - with: - java-version: ${{ matrix.java }} - distribution: 'temurin' - cache: 'maven' - check-latest: true - - name: Set up OSS Community Develocity Instance for Maven - uses: gradle/develocity-actions/setup-maven@v2.1 + - name: Checkout + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + - name: Setup Build Environment + uses: ./.github/actions/setup-build with: + java-version-tests: ${{ matrix.java-version }} + distribution: ${{ matrix.distribution }} develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} - - name: Install softhsm2 - run: sudo apt-get install -y softhsm2 - - name: Install opensc - run: sudo apt-get install -y opensc - - name: Ensure SoftHSM user configuration - run: impl/src/test/scripts/softhsm configure - - name: Populate SoftHSM with JJWT test keys - run: impl/src/test/scripts/softhsm import - name: Build # run a full build, just as we would for a release (i.e. the `ossrh` profile), but don't use gpg # to sign artifacts, since we don't want to mess with storing signing credentials in CI: - run: ${{env.MVN_CMD}} verify -Possrh -Dgpg.skip=true - - zulu: - strategy: - matrix: - java: [ '7', '8', '9', '11', '12', '13', '14', '15', '16', '17', '18', '21' ] - runs-on: 'ubuntu-latest' - env: - JDK_MAJOR_VERSION: ${{ matrix.java }} - name: jdk-${{ matrix.java }}-zulu - steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 - with: - java-version: ${{ matrix.java }} - distribution: 'zulu' - cache: 'maven' - check-latest: true - - name: Set up OSS Community Develocity Instance for Maven - uses: gradle/develocity-actions/setup-maven@v2.1 - with: - develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} - - name: Install softhsm2 - run: sudo apt-get install -y softhsm2 - - name: Install opensc - run: sudo apt-get install -y opensc - - name: Ensure SoftHSM user configuration - run: impl/src/test/scripts/softhsm configure - - name: Populate SoftHSM with JJWT test keys - run: impl/src/test/scripts/softhsm import - - name: Build - # run a full build, just as we would for a release (i.e. the `ossrh` profile), but don't use gpg - # to sign artifacts, since we don't want to mess with storing signing credentials in CI: - run: | - if [ "$JDK_MAJOR_VERSION" == "7" ]; then export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m"; fi - ${{env.MVN_CMD}} verify -Possrh -Dgpg.skip=true + run: ${{env.MVN_CMD}} verify -Possrh -Dgpg.skip=true -Dtest.jdk.version=${{ matrix.java-version }} # ensure all of our files have the correct/updated license header license-check: runs-on: 'ubuntu-latest' steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: - fetch-depth: 0 # avoid license plugin history warnings (plus it needs full history) - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: '8' - cache: 'maven' - check-latest: true - - name: Set up OSS Community Develocity Instance for Maven - uses: gradle/develocity-actions/setup-maven@v2.1 + fetch-depth: 0 + - name: Setup Build Environment + uses: ./.github/actions/setup-build with: develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} + setup-softhsm: 'false' - name: License Check - # This adds about 1 minute to any build, which is why we don't want to do it on every other build: - run: | - ${{env.MVN_CMD}} license:check + # This adds about 1 minute to any build, which is why we don't want to do it on every build: + run: ${{env.MVN_CMD}} license:check code-coverage: - needs: [oracle, temurin, zulu] runs-on: 'ubuntu-latest' steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: 'zulu' - java-version: '17' - cache: 'maven' - check-latest: true - - name: Set up OSS Community Develocity Instance for Maven - uses: gradle/develocity-actions/setup-maven@v2.1 + - name: Checkout + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + - name: Setup Build Environment + uses: ./.github/actions/setup-build with: develocity-access-key: ${{ secrets.DEVELOCITY_ACCESS_KEY }} - - name: Install softhsm2 - run: sudo apt-get install -y softhsm2 - - name: Install opensc - run: sudo apt-get install -y opensc - - name: Ensure SoftHSM user configuration - run: impl/src/test/scripts/softhsm configure - - name: Populate SoftHSM with JJWT test keys - run: impl/src/test/scripts/softhsm import - name: Code Coverage # run a full build, just as we would for a release (i.e. the `ossrh` profile), but don't use gpg # to sign artifacts, since we don't want to mess with storing signing credentials in CI: diff --git a/impl/src/test/groovy/io/jsonwebtoken/impl/security/JcaTemplateTest.groovy b/impl/src/test/groovy/io/jsonwebtoken/impl/security/JcaTemplateTest.groovy index bf1037276..549df50f6 100644 --- a/impl/src/test/groovy/io/jsonwebtoken/impl/security/JcaTemplateTest.groovy +++ b/impl/src/test/groovy/io/jsonwebtoken/impl/security/JcaTemplateTest.groovy @@ -266,12 +266,8 @@ class JcaTemplateTest { template.generatePrivate(new X509EncodedKeySpec(invalid)) fail() } catch (SecurityException expected) { - boolean jdk11OrLater = Classes.isAvailable('java.security.interfaces.XECPrivateKey') - String msg = 'KeyFactory callback execution failed: key spec not recognized' - if (jdk11OrLater) { - msg = 'KeyFactory callback execution failed: Only PKCS8EncodedKeySpec and XECPrivateKeySpec supported' - } - assertEquals msg, expected.getMessage() + String msg = expected.getMessage() + assertTrue msg, msg.startsWith('KeyFactory callback execution failed:') } } diff --git a/install-test-jdks.sh b/install-test-jdks.sh new file mode 100755 index 000000000..4aa0dc2c2 --- /dev/null +++ b/install-test-jdks.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# install-test-jdks.sh +# +# Installs all JDK versions needed to run the full multi-JDK test matrix locally via SDKMAN, +# then generates ~/.m2/toolchains.xml from the discovered JDKs. +# +# Usage: +# ./install-test-jdks.sh +# +# After running this script, activate each profile you want to test against, e.g.: +# ./mvnw verify -P jdk-8,jdk-11,jdk-21,jdk-25 +# +# The build JDK must be JDK 17+. If you are not already on JDK 17: +# sdk use java <17.x.x-tem> + +set -euo pipefail + +# ============================================================ +# JDK versions to install. +# Update these when new patch releases are available. +# Find current versions with: sdk list java +# +# NOTE: Temurin does not provide JDK 8 on all platforms (e.g. +# macOS/ARM). Zulu is used for JDK 8 as a reliable fallback. +# ============================================================ +JDKS=( + "8.0.492-zulu" # JDK 8 - minimum supported runtime + "11.0.31-tem" # JDK 11 + "17.0.19-tem" # JDK 17 - required build JDK + "21.0.11-tem" # JDK 21 + "25.0.3-tem" # JDK 25 +) +# ============================================================ + +if ! command -v sdk &>/dev/null; then + echo "ERROR: SDKMAN not found. Install it from https://sdkman.io" >&2 + exit 1 +fi + +# Source SDKMAN so 'sdk' commands work in this script +# shellcheck disable=SC1090 +source "${SDKMAN_DIR:-$HOME/.sdkman}/bin/sdkman-init.sh" + +echo "Installing test JDKs via SDKMAN..." +echo "(Already-installed versions will be skipped)" +echo + +for jdk in "${JDKS[@]}"; do + sdk install java "$jdk" || true +done + +echo +echo "Done. Generating ~/.m2/toolchains.xml from discovered JDKs..." +./mvnw --no-transfer-progress -q \ + org.apache.maven.plugins:maven-toolchains-plugin:3.2.0:generate-jdk-toolchains-xml \ + -Dtoolchain.file="${HOME}/.m2/toolchains.xml" + +echo +echo "To run the full multi-JDK test matrix:" +echo " ./mvnw verify -P jdk-8,jdk-11,jdk-17,jdk-21,jdk-25" +echo +echo "To run a single JDK profile (e.g., JDK 8 only):" +echo " ./mvnw verify -P jdk-8" diff --git a/pom.xml b/pom.xml index d5b8bc992..2207039fb 100644 --- a/pom.xml +++ b/pom.xml @@ -103,26 +103,31 @@ 3.3.1 3.2.8 0.23.1 + 3.2.0 4.2.1 4.6 true + + 8 + 8 + ${user.name}-${maven.build.timestamp} 2.19.2 20250517 2.13.1 - - + 1.84 bcprov-jdk18on bcpkix-jdk18on - 4.0.28 + 4.0.31 5.6.0 4.13.2 2.0.9 @@ -130,7 +135,9 @@ 3.1.2 4.5.2 ${jjwt.root}/target/clover/clover.db - + + false --add-opens java.base/java.lang=ALL-UNNAMED, --add-opens java.desktop/java.beans=ALL-UNNAMED, @@ -140,7 +147,7 @@ KeysTest.testKeyPairBuilder: --> --add-opens java.base/sun.security.util=ALL-UNNAMED - + ${test.addOpens} @@ -323,7 +330,8 @@ **/*.test.override **/*.bnd LICENSE - **/mvnw + **/mvnw + **/install-test-jdks.sh **/lombok.config .gitattributes **/genkeys @@ -365,16 +373,8 @@ ${jdk.version} true false - ${maven.javadoc.additionalOptions} + -html5 ${maven.javadoc.additionalOptions} - - - - commons-lang - commons-lang - 2.6 - - org.apache.maven.plugins @@ -463,7 +463,7 @@ - @@ -518,6 +518,22 @@ true + + enforce-java-17 + + enforce + + + + + + [17,) + Build requires JDK 17 or later. Use SDKMAN: sdk install java 17.x.x-tem + + + true + + @@ -525,7 +541,7 @@ maven-compiler-plugin ${maven.compiler.version} - ${jdk.version} + ${jdk.release.version} ${project.build.sourceEncoding} @@ -562,6 +578,9 @@ ${surefire.plugin.version} ${surefire.argLine} + + 1 + true @@ -649,28 +668,212 @@ + + + - - jdk9AndLater + skip-default-tests - [1.9,) + + test.jdk.version + - - false - -html5 - ${test.addOpens}, --illegal-access=debug - + + + + org.apache.maven.plugins + maven-surefire-plugin + + + default-test + + true + + + + + + + + - jdk17AndLater + jdk-8 - [17,) + + test.jdk.version + 8 + - - -html5 - ${test.addOpens} - + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + + test-jdk-8 + test + + + [1.8,1.9),[8,9) + + + + 1 + true + + + + + + + + + + jdk-11 + + + test.jdk.version + 11 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + + test-jdk-11 + test + + + 11 + + ${surefire.argLine} + + + + + + + + + + + + jdk-17 + + + test.jdk.version + 17 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + + test-jdk-17 + test + + ${surefire.argLine} + + + + + + + + + + + jdk-21 + + + test.jdk.version + 21 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + + test-jdk-21 + test + + + 21 + + ${surefire.argLine} + + + + + + + + + + + jdk-25 + + + test.jdk.version + 25 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + + test-jdk-25 + test + + + 25 + + ${surefire.argLine} + + + + + + + + docs