Reputation: 353
I am using JDK 11 and my application has around 20 projects. Now I want my maven to pick JAVA_HOME instead of changing all pom.xml with maven-compiler-plugin or by properties. I have set JAVA_HOME to JDK 11 Output of mvn -v
OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:28+0530)
Maven home: /home/krawler/apache-maven-3.0.5
Java version: 11.0.4, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-11-openjdk-11.0.4.11-0.el7_6.x86_64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.1.3.el7.x86_64", arch: "amd64", family: "unix"
But when I run mvn clean install I get below error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project mavenKwlCommonLibs: Compilation failure: Compilation failure:
[ERROR] error: Source option 5 is no longer supported. Use 6 or later.
[ERROR] error: Target option 1.5 is no longer supported. Use 1.6 or later.
Upvotes: 0
Views: 775
Reputation: 35805
There is a difference between the JDK you use and the Java version you compile for. You can very well compile for Java 8 with a JDK 11 (just one example).
You need to set
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
in your POM to the Java version you want to build for (see also https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html)
For Java 11, have also a look at https://stackoverflow.com/a/51586202/927493.
Upvotes: 2