Skip to content

Commit 50936b4

Browse files
authored
Java version check: only check >=11 (#12)
1 parent f0f5949 commit 50936b4

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

.github/workflows/build_standard.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ jobs:
4444
path: ./out
4545
if-no-files-found: error
4646

47-
validate_java_8:
47+
validate_java_11:
4848
runs-on: ubuntu-latest
4949
needs:
5050
- build
51-
5251
steps:
5352
- name: Download build
5453
uses: actions/download-artifact@v2
@@ -57,18 +56,17 @@ jobs:
5756
path: ./out
5857
- name: Grant execute permission for cm
5958
run: chmod +x ./out/bin/cm
60-
- name: Set up JDK 8
59+
- name: Set up JDK 11
6160
uses: actions/setup-java@v1
6261
with:
63-
java-version: 8
62+
java-version: 11
6463
- name: Execute to check if Java version is compatible
6564
run: ./out/bin/cm
6665

67-
validate_java_11:
66+
validate_java_17:
6867
runs-on: ubuntu-latest
6968
needs:
7069
- build
71-
7270
steps:
7371
- name: Download build
7472
uses: actions/download-artifact@v2
@@ -77,18 +75,17 @@ jobs:
7775
path: ./out
7876
- name: Grant execute permission for cm
7977
run: chmod +x ./out/bin/cm
80-
- name: Set up JDK 11
78+
- name: Set up JDK 17
8179
uses: actions/setup-java@v1
8280
with:
83-
java-version: 11
81+
java-version: 17
8482
- name: Execute to check if Java version is compatible
8583
run: ./out/bin/cm
8684

87-
validate_java_17:
85+
validate_java_21:
8886
runs-on: ubuntu-latest
8987
needs:
9088
- build
91-
9289
steps:
9390
- name: Download build
9491
uses: actions/download-artifact@v2
@@ -97,9 +94,9 @@ jobs:
9794
path: ./out
9895
- name: Grant execute permission for cm
9996
run: chmod +x ./out/bin/cm
100-
- name: Set up JDK 17
97+
- name: Set up JDK 21
10198
uses: actions/setup-java@v1
10299
with:
103-
java-version: 17
100+
java-version: 21
104101
- name: Execute to check if Java version is compatible
105-
run: ./out/bin/cm || if [ $? != 1 ]; then exit -1; fi
102+
run: ./out/bin/cm

src/main/java/org/contextmapper/cli/ContextMapperCLI.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
public class ContextMapperCLI {
2727

28-
private static final List<String> REQUIRED_JAVA_VERSIONS = Collections.unmodifiableList(Arrays.asList("11", "17"));
28+
private static final int REQUIRED_JAVA_VERSION = 11;
2929
private static final String VALIDATE_COMMAND = "validate";
3030
private static final String GENERATE_COMMAND = "generate";
3131

@@ -38,12 +38,12 @@ public ContextMapperCLI() {
3838
}
3939

4040
public static void main(String[] args) {
41-
String javaVersion = System.getProperty("java.version");
41+
int javaVersion = Runtime.version().feature();
4242

43-
if (REQUIRED_JAVA_VERSIONS.stream().anyMatch(javaVersion::startsWith)) {
43+
if (Runtime.version().feature() >= REQUIRED_JAVA_VERSION) {
4444
new ContextMapperCLI().run(args);
4545
} else {
46-
System.out.printf("Invalid Java version '%s', please set JAVA_HOME to major version '%s'%n", javaVersion, String.join("' or '", REQUIRED_JAVA_VERSIONS));
46+
System.out.printf("Invalid Java version '%s' (>=%s is required).", javaVersion, REQUIRED_JAVA_VERSION);
4747
System.exit(1);
4848
}
4949
}

0 commit comments

Comments
 (0)