Everytime I modify the dependencies inside the pom.xml
file in my IntelliJ Maven project, the Java version is set to 1.5
and I have to receonfigure my project.
The following settings are modified by Maven:
Settings
| Compiler
| Java Compiler
-> Target bytecode version
And Project Settings
| Modules
-> Language Level
Why is this happening and what do I have to do, so that maven doesn't vandalise my settings?
Alternatively, you can also change Java version for a Maven project by configuring the Maven compiler plugin as follows: [...] [...] This tells Java compiler to compile source code against Java version 11, and generate the .class files according to Java 15 format.
Before moving on, we can check the default JDK version of Maven. Running the mvn -v command will show the Java version in which Maven runs. Learn how to work with Maven profiles to be able to create different build configurations. Learn how to use the Maven compiler plugin, used to compile the source code of a Maven project. 2.
The first option is setting the version in compiler plugin properties: ? The Maven compiler accepts this command with – target and – source versions. If we want to use the Java 8 language features the – source should be set to 1.8. Also, for the compiled classes to be compatible with JVM 1.8, the – target value should be 1.8.
Running the mvn -v command will show the Java version in which Maven runs. Learn how to work with Maven profiles to be able to create different build configurations. Learn how to use the Maven compiler plugin, used to compile the source code of a Maven project. 2. Use the Compiler Plugin
You have to explicitely set the java version in your pom file so that version 1.5 doesn't get set by default.
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
Specify the java version under properties
.
<properties>
<java-version>1.8</java-version>
</properties>
and to use the same version with maven compile or package then include the same version in compile plug-in
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
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