When I do not define something as follows in my pom.xml file, where on my system is it defined for Maven which version of Java JDK to use while compiling (I have several versions installed on my system, JAVA_HOME
points to one of them)?
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
The Maven tool uses JDK version 11.0.
Method 1: Change the JAVA_HOME pathMaven uses the JAVA_HOME environment variable to find which Java version it is supposed to run. If a different version of Java is needed, set the JAVA_HOME to the path of the specific version of JDK.
Maven always uses the JDK specified by JAVA_HOME , no matter how many JDK installations are available on the system. This allows the user the flexibility to change JDKs as required or based on the project. Hence, it is important to ensure JAVA_HOME is defined.
Maven doc says
The Compiler Plugin is used to compile the sources of your project. The default compiler is javac and is used to compile Java sources. Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. If you want to change these defaults, you should set source and target as described in Setting the
-source
and-target
of the Java Compiler.
ref: http://maven.apache.org/plugins/maven-compiler-plugin/index.html
There is this interesting thread on Maven's Jira Change default source level to 1.5
EDIT:
Update for Maven 3.0 and later:
The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.tools.JavaCompiler (if you are using java 1.6) and is used to compile Java sources. If you want to force the plugin using javac, you must configure the plugin option forceJavacCompilerUse.
Source: http://maven.apache.org/plugins/maven-compiler-plugin/index.html
Thanks nachteil for pointing it out.
simply use properties
<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.test.skip>true</maven.test.skip>
</properties>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With