From 23eb7d18600a8ec58b5e96f5ce9cca05bffbfc30 Mon Sep 17 00:00:00 2001 From: Ryan Schmitt Date: Sat, 21 Mar 2026 10:01:35 -0700 Subject: [PATCH] Require Java 17+ for Maven runtime * Decouple the Maven runtime JDK from the compile/test toolchain by introducing `hc.build.toolchain.version` and overriding the inherited `use-toolchains` profile to select the toolchain from that property instead of `maven.compiler.source`. * Require Java 17 or newer to run Maven, but continue compiling and testing against Java 8, 11, 17, and 21 toolchains. * Update CI to install JDK 17 for the Maven process and the matrix JDK as the toolchain, generate `toolchains.xml`, and pass `hc.build.toolchain.version` explicitly instead of disabling toolchains and running everything on the host JDK. This does not drop support for Java 8 consumers: published artifacts still target Java 8 and the build can still compile and run tests on Java 8 through toolchains. --- .github/workflows/maven.yml | 40 +++++++++++++++++++++++-- pom.xml | 59 ++++++++++++++++++++++++++++++++++++- 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 3219d051d..f40f1e8b0 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -22,7 +22,6 @@ permissions: jobs: build: - runs-on: ${{ matrix.os }} strategy: matrix: @@ -43,10 +42,45 @@ jobs: key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- - - name: Set up JDK ${{ matrix.java }} + - name: Select JDK toolchain version + run: | + case '${{ matrix.java }}' in + 8) + echo 'HC_BUILD_TOOLCHAIN_VERSION=1.8' >> "$GITHUB_ENV" + ;; + *) + echo 'HC_BUILD_TOOLCHAIN_VERSION=${{ matrix.java }}' >> "$GITHUB_ENV" + ;; + esac + - name: Set up toolchain JDK ${{ matrix.java }} + id: setup-java-toolchain uses: actions/setup-java@v5 with: distribution: 'temurin' java-version: ${{ matrix.java }} + - name: Set up JDK 17 for Maven + uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: '17' + - name: Configure Maven toolchains + env: + TOOLCHAIN_JAVA_HOME: ${{ steps.setup-java-toolchain.outputs.path }} + run: | + mkdir -p "${HOME}/.m2" + cat > "${HOME}/.m2/toolchains.xml" < + + + jdk + + ${HC_BUILD_TOOLCHAIN_VERSION} + + + ${TOOLCHAIN_JAVA_HOME} + + + + EOF - name: Build with Maven - run: ./mvnw -V --file pom.xml --no-transfer-progress -DtrimStackTrace=false -Djunit.jupiter.execution.parallel.enabled=false -P-use-toolchains,docker + run: ./mvnw -V --file pom.xml --no-transfer-progress -DtrimStackTrace=false -Djunit.jupiter.execution.parallel.enabled=false -Dhc.build.toolchain.version="${HC_BUILD_TOOLCHAIN_VERSION}" -Pdocker diff --git a/pom.xml b/pom.xml index f50a666ce..c6ee1306c 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,8 @@ 1.8 1.8 true + + ${maven.compiler.source} 2.5.2 5.14.3 5.0.0 @@ -229,6 +231,27 @@ + + org.apache.maven.plugins + maven-enforcer-plugin + 3.5.0 + + + enforce-java-runtime + + enforce + + + + + [17,) + Apache HttpComponents Core requires Java 17 or newer to run Maven. Use toolchains to compile and test with older JDKs. + + + + + + com.github.siom79.japicmp japicmp-maven-plugin @@ -295,6 +318,40 @@ + + + use-toolchains + + + ${user.home}/.m2/toolchains.xml + + + + + + org.apache.maven.plugins + maven-toolchains-plugin + 3.2.0 + + + + ${hc.build.toolchain.version} + + + + + + + toolchain + + + + + + + + + @@ -391,4 +448,4 @@ - \ No newline at end of file +