Subrato Pattanaik
Subrato Pattanaik

Reputation: 6049

Change maven default java compliance level for new projects

I am using Eclipse IDE 2020-03. Whenever I created a maven project its default java compliance level is always 1.7. My JDK version is 11.

It is possible to set java compliance to 11 manually by following.

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <release>11</release>
    </configuration>
</plugin>

My concern is that I have to set this configuration everytime I create a new maven project.

Is there any solution where default java compliance of new maven project is set to my JDK version (here JDK 11) installed in my system?

Also I need some guidance about if I want to send this maven project whose JDK is 11 to other system where the JDK version is 8, will it work on other system?

Upvotes: 0

Views: 671

Answers (1)

J Fabian Meier
J Fabian Meier

Reputation: 35785

The Java version you compile for needs to be set somewhere in your POM.

If you have many projects, you can create a parent POM for all of those from which you inherit.

If the level is greater than the installed JDK (say you want to compile for Java 11 on a JDK1.8), the build will fail.

On the other hand, it is fine to e.g. compile for Java 11 with a JDK 14.

Upvotes: 1

Related Questions