Skip to content

Commit

Permalink
feat: simplify java selection mode
Browse files Browse the repository at this point in the history
- Default to Java 1.8 (Java 8)
- Provide a single legacy Java (8 and below) profile that sets the correct compiler flags
- Provide distinct build workflows for legacy and modern Java
- Default to Unicode file encoding for better consistency and modern standards
- Default to modern Java compiler syntax for an easier/simpler way forward
  • Loading branch information
Okeanos committed Dec 31, 2024
1 parent d7579ba commit 8816174
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 27 deletions.
55 changes: 29 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,72 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

# yaml-language-server:$schema=https://json.schemastore.org/github-workflow.json
name: Java CI with Maven

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
contents: read

jobs:
build-6:
legacy-java:
runs-on: ubuntu-latest
name: Java 6
strategy:
matrix:
java: [ 6, 8 ]
name: Java ${{ matrix.java }}
steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4
# JDK 11 is required for Maven itself as runtime
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: |
6
${{ matrix.java }}
11
- name: Setup Maven
run: |
mkdir -p .mvn
echo "-B" > .mvn/maven.config
- name: Compile with Java 6
run: mvn clean compile -Dmaven.toolchains.jdk.id=zulu_6 -P java-6,!legacy-java,!modern-java
- name: Run Tests with Java 6
run: mvn test -Dmaven.toolchains.jdk.id=zulu_6 -P java-6,!legacy-java,!modern-java
- name: Build Test Report for Java 6
- name: Compile with Java ${{ matrix.java }}
run: mvn clean compile -P=legacy-java -Djava.version="1.${{ matrix.java }}"
- name: Run Tests with Java ${{ matrix.java }}
run: mvn test -P=legacy-java -Djava.version="1.${{ matrix.java }}"
- name: Build Test Report for Java ${{ matrix.java }}
if: ${{ always() }}
run: |
mvn surefire-report:report-only
mvn site -DgenerateReports=false
- name: Upload Test Results for Java 6
- name: Upload Test Results for Java ${{ matrix.java }}
if: ${{ always() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Test Results for Java 6
name: Test Results for Java ${{ matrix.java }}
path: target/surefire-reports/
- name: Upload Test Report 6
- name: Upload Test Report ${{ matrix.java }}
if: ${{ always() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Test Report for Java 6
name: Test Report for Java ${{ matrix.java }}
path: target/site/

build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8, 11, 17 ]
java: [ 11, 17, 21 ]
name: Java ${{ matrix.java }}
steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: ${{ matrix.java }}
Expand All @@ -72,23 +75,23 @@ jobs:
mkdir -p .mvn
echo "-B" > .mvn/maven.config
- name: Compile with Java ${{ matrix.java }}
run: mvn clean compile
run: mvn clean compile -Djava.version="${{ matrix.java }}"
- name: Run Tests with Java ${{ matrix.java }}
run: mvn test
run: mvn test -Djava.version="${{ matrix.java }}"
- name: Build Test Report for Java ${{ matrix.java }}
if: ${{ always() }}
run: |
mvn surefire-report:report-only
mvn site -DgenerateReports=false
- name: Upload Test Results for Java ${{ matrix.java }}
if: ${{ always() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Test Results for Java ${{ matrix.java }}
path: target/surefire-reports/
- name: Upload Test Report ${{ matrix.java }}
if: ${{ always() }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Test Report for Java ${{ matrix.java }}
path: target/site/
51 changes: 50 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
<url>https://github.com/skyscreamer/JSONassert</url>

<properties>
<maven.compiler.release>8</maven.compiler.release>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>${project.build.sourceEncoding}</project.reporting.outputEncoding>
<maven.compiler.release>${java.version}</maven.compiler.release>
<maven.compiler.encoding>${project.build.sourceEncoding}</maven.compiler.encoding>
<toolchain.jdk.version>[${java.version},${parsedVersion.nextMajorVersion})</toolchain.jdk.version>
</properties>

<licenses>
Expand Down Expand Up @@ -62,11 +67,42 @@

<build>
<plugins>
<!--
This Plugin needs to go first so that the expected properties can be relied on by
e.g. the Maven Toolchains Plugin.
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<goals>
<goal>parse-version</goal>
</goals>
<configuration>
<versionString>${java.version}</versionString>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>select-jdk-toolchain</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down Expand Up @@ -100,6 +136,19 @@
</distributionManagement>

<profiles>
<profile>
<id>legacy-java</id>
<!-- Automatically activate if the runtime JDK is Java 8 or below -->
<activation>
<jdk>(,1.8]</jdk>
</activation>
<properties>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<!-- Unset the release flag that isn't supported by Java 8 and below -->
<maven.compiler.release></maven.compiler.release>
</properties>
</profile>
<profile>
<id>deploy</id>
<build>
Expand Down

0 comments on commit 8816174

Please sign in to comment.