Suzan Cioc
Suzan Cioc

Reputation: 30107

Why Maven project is tied to J2SE-1.5 by default?

If I create default empty based on no archetype Maven project in Eclipse, it will be based on J2SE-1.5.

enter image description here

I am to change manually both Build Path entry and code compliance.

Why?

How to make it be other?

Upvotes: 16

Views: 11100

Answers (3)

user1201626
user1201626

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.

  • Go to the folder .m2/repository/org/apache/maven/plugins/maven-compiler-plugin/3.1
  • Open maven-compiler-plugin-3.1.jar with a zip program.
  • Go to META-INF/maven and open the plugin.xml
  • 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.

  • Save the file and make sure it is written back to the zip file.

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

MariuszS
MariuszS

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

axtavt
axtavt

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

Related Questions