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.
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.
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-plugin
configuration:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With