Skip to content

Commit

Permalink
Merge branch 'templates/java-jdk8-pom-compat'
Browse files Browse the repository at this point in the history
Improve Java Builds with Conditional Compiler Options for JDK-8 Compatibility
  • Loading branch information
kilo52 authored Jan 6, 2024
2 parents 3e740e1 + e7348e2 commit 9be0441
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.
11 changes: 8 additions & 3 deletions java/01_executable/source/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<description>${{VAR_PROJECT_DESCRIPTION}}</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>${{VAR_JAVA_VERSION_POM}}</maven.compiler.target>
<maven.compiler.source>${{VAR_JAVA_VERSION_POM}}</maven.compiler.source>
${{VAR_POM_PROPERTIES}}
</properties>
<organization>
<name>${{VAR_PROJECT_ORGANISATION_NAME}}</name>
Expand All @@ -24,10 +23,15 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
<directory>build</directory>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<version>3.3.0</version>
<configuration>
<archive>
<manifest>
Expand All @@ -47,4 +51,5 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
</plugin>
</plugins>
</build>
${{VAR_POM_PROFILES}}
</project>
11 changes: 8 additions & 3 deletions java/02_library/source/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<description>${{VAR_PROJECT_DESCRIPTION}}</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>${{VAR_JAVA_VERSION_POM}}</maven.compiler.target>
<maven.compiler.source>${{VAR_JAVA_VERSION_POM}}</maven.compiler.source>
${{VAR_POM_PROPERTIES}}
</properties>
<organization>
<name>${{VAR_PROJECT_ORGANISATION_NAME}}</name>
Expand All @@ -24,10 +23,15 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
<directory>build</directory>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<version>3.3.0</version>
<executions>
<execution>
<id>default-jar</id>
Expand Down Expand Up @@ -89,4 +93,5 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
</plugin>
</plugins>
</build>
${{VAR_POM_PROFILES}}
</project>
8 changes: 4 additions & 4 deletions java/03_library_native_jni/source/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<description>${{VAR_PROJECT_DESCRIPTION}}</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>${{VAR_JAVA_VERSION_POM}}</maven.compiler.target>
<maven.compiler.source>${{VAR_JAVA_VERSION_POM}}</maven.compiler.source>
${{VAR_POM_PROPERTIES}}
</properties>
<organization>
<name>${{VAR_PROJECT_ORGANISATION_NAME}}</name>
Expand All @@ -26,7 +25,7 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.12.1</version>
<configuration>
<compilerArgs>
<arg>-h</arg>
Expand All @@ -37,7 +36,7 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<version>3.3.0</version>
<executions>
<execution>
<id>default-jar</id>
Expand Down Expand Up @@ -162,4 +161,5 @@ ${{INCLUDE:java/maven/dependencyUnitTests.xml}}
</plugin>
</plugins>
</build>
${{VAR_POM_PROFILES}}
</project>
16 changes: 14 additions & 2 deletions java/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (C) 2023 Raven Computing
# Copyright (C) 2024 Raven Computing
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,7 +51,6 @@ function process_files_lvl_1() {
replace_var "PROJECT_ARTIFACT_ID" "$var_project_artifact_id";
replace_var "JAVA_VERSION" "$var_java_version";
replace_var "JAVA_VERSION_LABEL" "$var_java_version_label";
replace_var "JAVA_VERSION_POM" "$var_java_version_pom";
replace_var "NAMESPACE_DECLARATION" "$var_namespace";
replace_var "NAMESPACE_DECLARATION_0" "$var_namespace_0";
replace_var "NAMESPACE_DECLARATION_TRAILING_SEP" "$var_namespace_trailing_sep";
Expand All @@ -60,6 +59,19 @@ function process_files_lvl_1() {
logW "Docker integration is not yet supported when using JDK 21";
fi

# Check for Java 8 compatibility requirement and adjust the POM based on that.
if [[ "$var_java_version" == "1.8" ]]; then
replace_var "POM_PROPERTIES" "";
load_var_from_file "POM_PROFILES";
replace_var "POM_PROFILES" "$VAR_FILE_VALUE";
else
load_var_from_file "POM_PROPERTIES";
replace_var "POM_PROPERTIES" "$VAR_FILE_VALUE";
replace_var "POM_PROFILES" "";
fi

replace_var "JAVA_VERSION_POM" "$var_java_version_pom";

if [ -z "$var_namespace" ]; then
replace_var "NAMESPACE_PACKAGE_DECLARATION" "";
else
Expand Down
21 changes: 21 additions & 0 deletions java/var/pom_profiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<profiles>
<profile>
<id>compiler-jdk8-compat</id>
<activation>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
</profile>
<profile>
<id>compiler-java8-release</id>
<activation>
<jdk>[9,)</jdk>
</activation>
<properties>
<maven.compiler.release>8</maven.compiler.release>
</properties>
</profile>
</profiles>
1 change: 1 addition & 0 deletions java/var/pom_properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<maven.compiler.release>${{VAR_JAVA_VERSION_POM}}</maven.compiler.release>

0 comments on commit 9be0441

Please sign in to comment.