Dave The Dane
Dave The Dane

Reputation: 889

How to set the DEFAULT maven Java Version

I am tired of editing pom.xml for every new project & adding:
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
The Default - 1.5 - is unsupported & was last publicly updated 8 years ago.
So where is the option to automatically generate the above into pom.xml?
I use Eclipse as IDE.
I've seen suggestions that this can be achieved by changing settings.xml.
I have not had any success there, so if you're posting a solution, please post a tried a tested example in its entirety.
Also, please remember, my objective is to get the above 2 lines generated into pom.xml when creating a new project, not just to change the default compiler.

Upvotes: 0

Views: 129

Answers (1)

Milen Dyankov
Milen Dyankov

Reputation: 3062

Inside <profiles> of your settings.xml add

<profile>
    <id>java8</id>
    <activation>
            <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</profile>

To check it is applied properly, go to your project and run mvn help:effective-pom command! You should see it in the displayed pom!

Upvotes: 1

Related Questions