Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different ways to override java version specified in parent pom

I'm using a parent pom which establishes java version to 1.5. In my concrete project I use 1.6 so I was changing the compiler version in eclipse each time I did a Maven Update.

Looking for a solution to this I found some solutions involving overriding the behavior of the parent pom in the child one.

My question is if there are any differences between them and if so, which option should I use. The options I found (perhaps there are more) are:

  • In properties tag: <app.java.version>1.6</app.java.version>
  • In properties tag: <jdk.version>1.6</jdk.version>
  • In configuration tag: <source>${jdk.version}</source>

I'm very new to Maven. Thanks in advance.

like image 838
javi_swift Avatar asked Sep 17 '25 08:09

javi_swift


2 Answers

You definitely want to go with:

<properties>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
</properties>

It is the de facto standard Maven property for setting up Java version and it's used not only by maven-compiler-plugin but also by other standard Maven plugins (including reporting ones), so this applies your Java version globally, not only for compiling classes.

like image 171
Michał Kalinowski Avatar answered Sep 19 '25 07:09

Michał Kalinowski


Properties are just properties, which do not mean much unless you use them somewhere.
The important thing is that you set the version in the maven-compiler-pluginconfiguration:

<properties>
    <jdk.version>1.6</jdk.version>
</properties>

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
            <source>${jdk.version}</source>
            <target>${jdk.version}</target>
        </configuration>
    </plugin>
</plugins>
like image 23
Kuurde Avatar answered Sep 19 '25 07:09

Kuurde