diff --git a/.github/workflows/build_standard.yml b/.github/workflows/build_standard.yml index bea33de..3fc9db1 100644 --- a/.github/workflows/build_standard.yml +++ b/.github/workflows/build_standard.yml @@ -44,11 +44,10 @@ jobs: path: ./out if-no-files-found: error - validate_java_8: + validate_java_11: runs-on: ubuntu-latest needs: - build - steps: - name: Download build uses: actions/download-artifact@v2 @@ -57,18 +56,17 @@ jobs: path: ./out - name: Grant execute permission for cm run: chmod +x ./out/bin/cm - - name: Set up JDK 8 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 8 + java-version: 11 - name: Execute to check if Java version is compatible run: ./out/bin/cm - validate_java_11: + validate_java_17: runs-on: ubuntu-latest needs: - build - steps: - name: Download build uses: actions/download-artifact@v2 @@ -77,18 +75,17 @@ jobs: path: ./out - name: Grant execute permission for cm run: chmod +x ./out/bin/cm - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Execute to check if Java version is compatible run: ./out/bin/cm - validate_java_17: + validate_java_21: runs-on: ubuntu-latest needs: - build - steps: - name: Download build uses: actions/download-artifact@v2 @@ -97,9 +94,9 @@ jobs: path: ./out - name: Grant execute permission for cm run: chmod +x ./out/bin/cm - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 17 + java-version: 21 - name: Execute to check if Java version is compatible - run: ./out/bin/cm || if [ $? != 1 ]; then exit -1; fi + run: ./out/bin/cm diff --git a/src/main/java/org/contextmapper/cli/ContextMapperCLI.java b/src/main/java/org/contextmapper/cli/ContextMapperCLI.java index d455a3c..de72e04 100644 --- a/src/main/java/org/contextmapper/cli/ContextMapperCLI.java +++ b/src/main/java/org/contextmapper/cli/ContextMapperCLI.java @@ -25,7 +25,7 @@ public class ContextMapperCLI { - private static final List REQUIRED_JAVA_VERSIONS = Collections.unmodifiableList(Arrays.asList("11", "17")); + private static final int REQUIRED_JAVA_VERSION = 11; private static final String VALIDATE_COMMAND = "validate"; private static final String GENERATE_COMMAND = "generate"; @@ -38,12 +38,12 @@ public ContextMapperCLI() { } public static void main(String[] args) { - String javaVersion = System.getProperty("java.version"); + int javaVersion = Runtime.version().feature(); - if (REQUIRED_JAVA_VERSIONS.stream().anyMatch(javaVersion::startsWith)) { + if (Runtime.version().feature() >= REQUIRED_JAVA_VERSION) { new ContextMapperCLI().run(args); } else { - System.out.printf("Invalid Java version '%s', please set JAVA_HOME to major version '%s'%n", javaVersion, String.join("' or '", REQUIRED_JAVA_VERSIONS)); + System.out.printf("Invalid Java version '%s' (>=%s is required).", javaVersion, REQUIRED_JAVA_VERSION); System.exit(1); } }