In this post, We will learn about Compiling the Maven project with different JDK versions?
Usually, by default, maven 2 supports JDK 1.4, and maven 3 uses JDK 1.5 to compile the project. Which is really too old. Maven comes with a Compiler Plugin, This compiler plugin helps maven to compile the project source code with a particular JDK version.
Solution
We may configure the plugin compiler directly in pom.xml (Tested with Maven 2 and 3)
pom.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<project> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.9</source> <target>1.9</target> </configuration> </plugin> </plugins> </build> </project> |
Alternatively, We can configure the java version via the property values. (Tested with Maven 3)
pom.xml
1 2 3 4 |
<properties> <maven.compiler.target>1.6</maven.compiler.target> <maven.compiler.source>1.6</maven.compiler.source> </properties> |
That’s all about Compiling the Maven project with different JDK versions?
If you have any feedback or suggestion please feel free to drop in below comment box.