Skip to content

Commit 9be0441

Browse files
authored
Merge branch 'templates/java-jdk8-pom-compat'
Improve Java Builds with Conditional Compiler Options for JDK-8 Compatibility
2 parents 3e740e1 + e7348e2 commit 9be0441

File tree

6 files changed

+56
-12
lines changed

6 files changed

+56
-12
lines changed

java/01_executable/source/pom.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
<description>${{VAR_PROJECT_DESCRIPTION}}</description>
1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<maven.compiler.target>${{VAR_JAVA_VERSION_POM}}</maven.compiler.target>
14-
<maven.compiler.source>${{VAR_JAVA_VERSION_POM}}</maven.compiler.source>
13+
${{VAR_POM_PROPERTIES}}
1514
</properties>
1615
<organization>
1716
<name>${{VAR_PROJECT_ORGANISATION_NAME}}</name>
@@ -24,10 +23,15 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
2423
<directory>build</directory>
2524
<finalName>${project.artifactId}-${project.version}</finalName>
2625
<plugins>
26+
<plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-compiler-plugin</artifactId>
29+
<version>3.12.1</version>
30+
</plugin>
2731
<plugin>
2832
<groupId>org.apache.maven.plugins</groupId>
2933
<artifactId>maven-jar-plugin</artifactId>
30-
<version>2.4</version>
34+
<version>3.3.0</version>
3135
<configuration>
3236
<archive>
3337
<manifest>
@@ -47,4 +51,5 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
4751
</plugin>
4852
</plugins>
4953
</build>
54+
${{VAR_POM_PROFILES}}
5055
</project>

java/02_library/source/pom.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
<description>${{VAR_PROJECT_DESCRIPTION}}</description>
1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<maven.compiler.target>${{VAR_JAVA_VERSION_POM}}</maven.compiler.target>
14-
<maven.compiler.source>${{VAR_JAVA_VERSION_POM}}</maven.compiler.source>
13+
${{VAR_POM_PROPERTIES}}
1514
</properties>
1615
<organization>
1716
<name>${{VAR_PROJECT_ORGANISATION_NAME}}</name>
@@ -24,10 +23,15 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
2423
<directory>build</directory>
2524
<finalName>${project.artifactId}-${project.version}</finalName>
2625
<plugins>
26+
<plugin>
27+
<groupId>org.apache.maven.plugins</groupId>
28+
<artifactId>maven-compiler-plugin</artifactId>
29+
<version>3.12.1</version>
30+
</plugin>
2731
<plugin>
2832
<groupId>org.apache.maven.plugins</groupId>
2933
<artifactId>maven-jar-plugin</artifactId>
30-
<version>2.4</version>
34+
<version>3.3.0</version>
3135
<executions>
3236
<execution>
3337
<id>default-jar</id>
@@ -89,4 +93,5 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
8993
</plugin>
9094
</plugins>
9195
</build>
96+
${{VAR_POM_PROFILES}}
9297
</project>

java/03_library_native_jni/source/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
<description>${{VAR_PROJECT_DESCRIPTION}}</description>
1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<maven.compiler.target>${{VAR_JAVA_VERSION_POM}}</maven.compiler.target>
14-
<maven.compiler.source>${{VAR_JAVA_VERSION_POM}}</maven.compiler.source>
13+
${{VAR_POM_PROPERTIES}}
1514
</properties>
1615
<organization>
1716
<name>${{VAR_PROJECT_ORGANISATION_NAME}}</name>
@@ -26,7 +25,7 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
2625
<plugins>
2726
<plugin>
2827
<artifactId>maven-compiler-plugin</artifactId>
29-
<version>3.10.1</version>
28+
<version>3.12.1</version>
3029
<configuration>
3130
<compilerArgs>
3231
<arg>-h</arg>
@@ -37,7 +36,7 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
3736
<plugin>
3837
<groupId>org.apache.maven.plugins</groupId>
3938
<artifactId>maven-jar-plugin</artifactId>
40-
<version>2.4</version>
39+
<version>3.3.0</version>
4140
<executions>
4241
<execution>
4342
<id>default-jar</id>
@@ -162,4 +161,5 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
162161
</plugin>
163162
</plugins>
164163
</build>
164+
${{VAR_POM_PROFILES}}
165165
</project>

java/init.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright (C) 2023 Raven Computing
2+
# Copyright (C) 2024 Raven Computing
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -51,7 +51,6 @@ function process_files_lvl_1() {
5151
replace_var "PROJECT_ARTIFACT_ID" "$var_project_artifact_id";
5252
replace_var "JAVA_VERSION" "$var_java_version";
5353
replace_var "JAVA_VERSION_LABEL" "$var_java_version_label";
54-
replace_var "JAVA_VERSION_POM" "$var_java_version_pom";
5554
replace_var "NAMESPACE_DECLARATION" "$var_namespace";
5655
replace_var "NAMESPACE_DECLARATION_0" "$var_namespace_0";
5756
replace_var "NAMESPACE_DECLARATION_TRAILING_SEP" "$var_namespace_trailing_sep";
@@ -60,6 +59,19 @@ function process_files_lvl_1() {
6059
logW "Docker integration is not yet supported when using JDK 21";
6160
fi
6261

62+
# Check for Java 8 compatibility requirement and adjust the POM based on that.
63+
if [[ "$var_java_version" == "1.8" ]]; then
64+
replace_var "POM_PROPERTIES" "";
65+
load_var_from_file "POM_PROFILES";
66+
replace_var "POM_PROFILES" "$VAR_FILE_VALUE";
67+
else
68+
load_var_from_file "POM_PROPERTIES";
69+
replace_var "POM_PROPERTIES" "$VAR_FILE_VALUE";
70+
replace_var "POM_PROFILES" "";
71+
fi
72+
73+
replace_var "JAVA_VERSION_POM" "$var_java_version_pom";
74+
6375
if [ -z "$var_namespace" ]; then
6476
replace_var "NAMESPACE_PACKAGE_DECLARATION" "";
6577
else

java/var/pom_profiles

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<profiles>
2+
<profile>
3+
<id>compiler-jdk8-compat</id>
4+
<activation>
5+
<jdk>1.8</jdk>
6+
</activation>
7+
<properties>
8+
<maven.compiler.target>1.8</maven.compiler.target>
9+
<maven.compiler.source>1.8</maven.compiler.source>
10+
</properties>
11+
</profile>
12+
<profile>
13+
<id>compiler-java8-release</id>
14+
<activation>
15+
<jdk>[9,)</jdk>
16+
</activation>
17+
<properties>
18+
<maven.compiler.release>8</maven.compiler.release>
19+
</properties>
20+
</profile>
21+
</profiles>

java/var/pom_properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<maven.compiler.release>${{VAR_JAVA_VERSION_POM}}</maven.compiler.release>

0 commit comments

Comments
 (0)