Reputation: 30107
If I create default empty based on no archetype Maven
project in Eclipse
, it will be based on J2SE-1.5
.
I am to change manually both Build Path entry and code compliance.
Why?
How to make it be other?
Upvotes: 16
Views: 11100
Reputation: 49
If you want to make sure that newly created projects in Eclipse use another default java version than Java 1.5, you can change the configuration in the maven-compiler-plugin.
In the following lines:
<source implementation="java.lang.String" default-value="1.5">${maven.compiler.source}</source>
<target implementation="java.lang.String" default-value="1.5">${maven.compiler.target}</target>
change the default-value to 1.7 or 1.8 or whatever you like.
From now on, all new Maven projects use the java version you specified.
Information is from the following blog post: https://sandocean.wordpress.com/2019/03/22/directly-generating-maven-projects-in-eclipse-with-java-version-newer-than-1-5/
Upvotes: 1
Reputation: 31587
@axtavt is right, add source level configuration to your project. But do not configure maven-compiler-plugin
, simply put this properties into pom.xml
.
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
After this refresh maven configuration in Eclipse.
Upvotes: 17
Reputation: 242706
It's consistent with source
and target
settings of maven-compiler-plugin
, which are 1.5
by default.
If you change them, generated project will use different version of as well:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Note that if you change compliance settings of Eclipse project without changing of maven-compiler-plugin
settings, your Maven builds would be inconsistent with your Eclipse environment.
Upvotes: 7