Guide for Supporting Multiple Versions of Java (8, 11, 14) in Your Maven Project
In this article, see a guide for supporting multiple versions of Java in your Maven project.
Join the DZone community and get the full member experience.
Join For FreeThe new version of Java is here! But you cannot migrate at this moment, that is not a problem, because you can do it partially.
If this is you problem, then you are in right place. :)
In this article, you will see how to support multiple versions of Java in a Maven project.
Prerequisites
- Installed Maven
- Installed multiple versions of Java
Steps for Supporting Multiple Java Versions
- Create toolchains.xml file
- Possible locations for toolchains.xml
- Add Maven Toolchains dependency in parent .pom
- Add configuration for specific JDK version in modules
- First module, use the feature from JDK 8 and simple JUnit test
- Second module, use the feature from JDK 11 and simple JUnit test
- Third module, use the feature from JDK 14 and simple JUnit test
- Execute 'mvn clean install' and check logs
- Check Java 14 features in IntelliJ
- Source code for this example
Install Maven
Start by updating the package index:
xxxxxxxxxx
sudo apt update
Next, install Maven by typing the following command:
xxxxxxxxxx
sudo apt install maven
Verify the installation by running the mvn -version command:
xxxxxxxxxx
mvn -version
Install Multiple Java Versions
First, update the apt package index with:
xxxxxxxxxx
sudo apt update
Once the package index is updated install the default Java OpenJDK package with:
xxxxxxxxxx
sudo apt install default-jdk
Verify the installation, by running the following command which will print the Java version:
xxxxxxxxxx
java -version
The output will look something like this:
xxxxxxxxxx
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment (build 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.2+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)
Note: Repeat process for all versions of Java, which are required for your specific case.
Steps for Supporting Multiple Java Versions
Create toolchains.xml file
This file will be used in 'maven-toolchains-plugin' and whole configuration for jdk version should be in this file.
xxxxxxxxxx
<toolchains>
<!-- JDK toolchains -->
<toolchain>
<type>jdk</type>
<provides>
<version>8</version>
</provides>
<configuration>
<jdkHome>/usr/lib/jvm/java-8-openjdk-amd64/jre</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>11</version>
</provides>
<configuration>
<jdkHome>/home/sasa/Downloads/jdk11/amazon-corretto-11.0.6.10.1-linux-x64</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>14</version>
</provides>
<configuration>
<jdkHome>/home/sasa/Downloads/jdk11/jdk-14</jdkHome>
</configuration>
</toolchain>
<!-- other toolchains -->
</toolchains>
Possible Locations for toolchains.xml
Case 1: This file can be located in your ~/.m2 when configuration is user based
Case 2: This file can be located in {maven_home}/conf
Case 3: Can be added as parameter while executing maven command
Add Maven Toolchains Dependency in parent .pom
Parent pom in this example looks like:
xxxxxxxxxx
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sasa.multipleversions.examples</groupId>
<artifactId>multiple-java-versions</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>module-jdk-8</module>
<module>module-jdk-11</module>
<module>module-jdk-14</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
<configuration>
<toolchains>
<jdk>
<version>8</version>
</jdk>
</toolchains>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Add Configuration for Specific JDK Version in Modules
Toolchains configuration in .pom file for JDK8 module:
xxxxxxxxxx
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sasa.multipleversions.examples</groupId>
<artifactId>multiple-java-versions</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>module-jdk-8</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
<configuration>
<toolchains>
<jdk>
<version>8</version>
</jdk>
</toolchains>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Toolchains configuration in .pom file for JDK11 module:
xxxxxxxxxx
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sasa.multipleversions.examples</groupId>
<artifactId>multiple-java-versions</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>module-jdk-11</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
<configuration>
<toolchains>
<jdk>
<version>11</version>
</jdk>
</toolchains>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Toolchains configuration in .pom file for JDK14 module:
x
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sasa.multipleversions.examples</groupId>
<artifactId>multiple-java-versions</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>module-jdk-14</artifactId>
<properties>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>14</release>
<compilerArgs>
--enable-preview
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<argLine>--enable-preview</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
<configuration>
<toolchains>
<jdk>
<version>14</version>
</jdk>
</toolchains>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
-
In the first module, use the feature from JDK 8 and simple JUnit test.
Simple JDK8 feature:
xxxxxxxxxx
package com.multipleversion;
import javax.validation.Valid;
import java.util.function.IntFunction;
public class TestJdk8 {
public TestJdk8() {
IntFunction<Integer> doubleIt1 = ( final int x) -> x * 2; // Compiles since Java 8
// IntFunction<Integer> doubleIt2 = (@Valid final var x) -> x * 2; // Will compile from Java 11
System.out.println("TestJdk8: " + doubleIt1.apply(5));
}
}
Simple test without any assert:
xxxxxxxxxx
package com.multipleversion;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class Test8 {
public static void init() {
System.out.println("");
System.out.println("");
System.out.println("#######################################################################################");
System.out.println("");
}
public void finalize() {
System.out.println("");
System.out.println("#######################################################################################");
System.out.println("");
System.out.println("");
}
public void testJdk8() {
System.out.println("Test JDK 8");
System.out.println("");
TestJdk8 testJdk8 = new TestJdk8();
}
}
Second module, use the feature from JDK 11 and simple JUnit test.
Simple JDK11 feature:
xxxxxxxxxx
package com.multipleversion;
import javax.validation.Valid;
import java.util.function.IntFunction;
public class TestJdk11 {
public TestJdk11() {
// IntFunction<Integer> doubleIt1 = (@Valid final int x) -> x * 2; // Compiles since Java 8
// We are using 'var' instead of 'int'
IntFunction<Integer> doubleIt2 = ( final var x) -> x * 2; // Will compile from Java 11
System.out.println("TestJdk11: " + doubleIt2.apply(5));
}
}
Simple test without any assert:
xxxxxxxxxx
package com.multipleversion;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class Test11 {
public static void init() {
System.out.println("");
System.out.println("");
System.out.println("#######################################################################################");
System.out.println("");
}
public void finalize() {
System.out.println("");
System.out.println("#######################################################################################");
System.out.println("");
System.out.println("");
}
public void testJdk11() {
System.out.println("Test JDK 11");
System.out.println("");
TestJdk11 testJdk11 = new TestJdk11();
}
}
Third module, use the feature from JDK 14 and simple JUnit test
Simple JDK14 feature:
xxxxxxxxxx
package com.multipleversion;
public class TestJdk14 {
public TestJdk14(Object obj) {
if (obj instanceof String s) { // instanceof, cast and bind variable in one line.
if ("jdk14".equalsIgnoreCase(s)) {
System.out.println("Equals");
} else {
System.out.println("Not Equals");
}
} else {
System.out.println("Not a string");
}
}
}
Simple test without any assert:
xxxxxxxxxx
package com.multipleversion;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class Test14 {
public static void init() {
System.out.println("");
System.out.println("");
System.out.println("#######################################################################################");
System.out.println("");
}
public void finalize() {
System.out.println("");
System.out.println("#######################################################################################");
System.out.println("");
System.out.println("");
}
public void testJdk14() {
System.out.println("Test JDK 14");
System.out.println("");
TestJdk14 testJdk = new TestJdk14("jdk14");
TestJdk14 testJdk2 = new TestJdk14("jdk16");
TestJdk14 testJdk3 = new TestJdk14(1);
}
}
Execute 'mvn clean install' and check logs.
After successful execution you will get logs like:
xxxxxxxxxx
...
[INFO] Reactor Summary:
[INFO]
[INFO] multiple-java-versions ............................. SUCCESS [ 0.673 s]
[INFO] module-jdk-8 ....................................... SUCCESS [ 3.710 s]
[INFO] module-jdk-11 ...................................... SUCCESS [ 2.918 s]
[INFO] module-jdk-14 ...................................... SUCCESS [ 2.762 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10.262 s
[INFO] Finished at: 2020-04-04T14:57:36+02:00
[INFO] Final Memory: 13M/237M
[INFO] ------------------------------------------------------------------------
First module is working with JDK8 and this is visible in logs of successful build:
xxxxxxxxxx
...
[INFO] ------------------------------------------------------------------------
[INFO] Building module-jdk-8 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module-jdk-8 ---
[INFO]
[INFO] --- maven-toolchains-plugin:3.0.0:toolchain (default) @ module-jdk-8 ---
[INFO] Required toolchain: jdk [ version='8' ]
[INFO] Found matching toolchain for type jdk: JDK[/usr/lib/jvm/java-8-openjdk-amd64/jre]
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ module-jdk-8 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-8/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ module-jdk-8 ---
[INFO] Toolchain in maven-compiler-plugin: JDK[/usr/lib/jvm/java-8-openjdk-amd64/jre]
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-8/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ module-jdk-8 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-8/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ module-jdk-8 ---
[INFO] Toolchain in maven-compiler-plugin: JDK[/usr/lib/jvm/java-8-openjdk-amd64/jre]
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-8/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ module-jdk-8 ---
[INFO] Toolchain in maven-surefire-plugin: JDK[/usr/lib/jvm/java-8-openjdk-amd64/jre]
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.multipleversion.Test8
#######################################################################################
Test JDK 8
TestJdk8: 10
#######################################################################################
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.034 s - in com.multipleversion.Test8
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ module-jdk-8 ---
[INFO] Building jar: /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-8/target/module-jdk-8-1.0.0.jar
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ module-jdk-8 ---
[INFO] Installing /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-8/target/module-jdk-8-1.0.0.jar to /home/sasa/.m2/repository/com/sasa/multipleversions/examples/module-jdk-8/1.0.0/module-jdk-8-1.0.0.jar
[INFO] Installing /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-8/pom.xml to /home/sasa/.m2/repository/com/sasa/multipleversions/examples/module-jdk-8/1.0.0/module-jdk-8-1.0.0.pom
[INFO]
...
From logs is visible that module-jdk-8 is using maven-toolchains-plugin and set JDK version 8:
xxxxxxxxxx
[INFO] --- maven-toolchains-plugin:3.0.0:toolchain (default) @ module-jdk-8 ---
[INFO] Required toolchain: jdk [ version='8' ]
[INFO] Found matching toolchain for type jdk: JDK[/usr/lib/jvm/java-8-openjdk-amd64/jre]
The second module is working with JDK11 and this is visible in logs of successful build:
xxxxxxxxxx
...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building module-jdk-11 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module-jdk-11 ---
[INFO]
[INFO] --- maven-toolchains-plugin:3.0.0:toolchain (default) @ module-jdk-11 ---
[INFO] Required toolchain: jdk [ version='11' ]
[INFO] Found matching toolchain for type jdk: JDK[/home/sasa/Downloads/jdk11/amazon-corretto-11.0.6.10.1-linux-x64]
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ module-jdk-11 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-11/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ module-jdk-11 ---
[INFO] Toolchain in maven-compiler-plugin: JDK[/home/sasa/Downloads/jdk11/amazon-corretto-11.0.6.10.1-linux-x64]
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-11/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ module-jdk-11 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-11/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ module-jdk-11 ---
[INFO] Toolchain in maven-compiler-plugin: JDK[/home/sasa/Downloads/jdk11/amazon-corretto-11.0.6.10.1-linux-x64]
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-11/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ module-jdk-11 ---
[INFO] Toolchain in maven-surefire-plugin: JDK[/home/sasa/Downloads/jdk11/amazon-corretto-11.0.6.10.1-linux-x64]
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.multipleversion.Test11
#######################################################################################
Test JDK 11
TestJdk11: 10
#######################################################################################
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.06 s - in com.multipleversion.Test11
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ module-jdk-11 ---
[INFO] Building jar: /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-11/target/module-jdk-11-1.0.0.jar
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ module-jdk-11 ---
[INFO] Installing /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-11/target/module-jdk-11-1.0.0.jar to /home/sasa/.m2/repository/com/sasa/multipleversions/examples/module-jdk-11/1.0.0/module-jdk-11-1.0.0.jar
[INFO] Installing /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-11/pom.xml to /home/sasa/.m2/repository/com/sasa/multipleversions/examples/module-jdk-11/1.0.0/module-jdk-11-1.0.0.pom
[INFO]
...
From logs is visible that module-jdk-11 is using maven-toolchains-plugin and set JDK version 11:
xxxxxxxxxx
[INFO] --- maven-toolchains-plugin:3.0.0:toolchain (default) @ module-jdk-11 ---
[INFO] Required toolchain: jdk [ version='11' ]
[INFO] Found matching toolchain for type jdk: JDK[/home/sasa/Downloads/jdk11/amazon-corretto-11.0.6.10.1-linux-x64]
The third module is working with JDK14 and this is visible in logs of successful build:
xxxxxxxxxx
...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building module-jdk-14 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) module-jdk-14 ---
[INFO]
[INFO] --- maven-toolchains-plugin:3.0.0:toolchain (default) module-jdk-14 ---
[INFO] Required toolchain: jdk [ version='14' ]
[INFO] Found matching toolchain for type jdk: JDK[/home/sasa/Downloads/jdk11/jdk-14]
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) module-jdk-14 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-14/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) module-jdk-14 ---
[INFO] Toolchain in maven-compiler-plugin: JDK[/home/sasa/Downloads/jdk11/jdk-14]
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-14/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) module-jdk-14 ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-14/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) module-jdk-14 ---
[INFO] Toolchain in maven-compiler-plugin: JDK[/home/sasa/Downloads/jdk11/jdk-14]
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-14/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) module-jdk-14 ---
[INFO] Toolchain in maven-surefire-plugin: JDK[/home/sasa/Downloads/jdk11/jdk-14]
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.multipleversion.Test14
#######################################################################################
Test JDK 14
Equals
Not Equals
Not a string
#######################################################################################
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.049 s - in com.multipleversion.Test14
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) module-jdk-14 ---
[INFO] Building jar: /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-14/target/module-jdk-14-1.0.0.jar
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) module-jdk-14 ---
[INFO] Installing /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-14/target/module-jdk-14-1.0.0.jar to /home/sasa/.m2/repository/com/sasa/multipleversions/examples/module-jdk-14/1.0.0/module-jdk-14-1.0.0.jar
[INFO] Installing /home/sasa/Sasa Podaci/Podaci/Develpoment/dzone-article/test/multiple-java-versions/module-jdk-14/pom.xml to /home/sasa/.m2/repository/com/sasa/multipleversions/examples/module-jdk-14/1.0.0/module-jdk-14-1.0.0.pom
...
From logs is visible that module-jdk-14 is using maven-toolchains-plugin and set JDK version 14:
xxxxxxxxxx
[INFO] --- maven-toolchains-plugin:3.0.0:toolchain (default) module-jdk-14 ---
[INFO] Required toolchain: jdk [ version='14' ]
[INFO] Found matching toolchain for type jdk: JDK[/home/sasa/Downloads/jdk11/jdk-14]
Check Java 14 Features in IntelliJ
https://blog.jetbrains.com/
Source Code for This Example
Opinions expressed by DZone contributors are their own.
Comments