4

There could be two different properties as of specifying java version in maven properties:

<properties>
    <java.version>7</java.version>
</properties>

and

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

What is the difference and when to use what?

Mike
  • 18,562
  • 24
  • 92
  • 124

1 Answers1

1

These two ways of configuring the Java version produces exactly the same result.

1) This is the standard Maven way to value source and target Java versions :

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

2) While that is a Spring Boot specificity :

<properties>
    <java.version>7</java.version>
</properties>

It is a shortcut property to not declare both the source and the target version as these have the same value.

From the spring-boot-starter-parent pom, we can see that java.version is used to value maven.compiler.source and maven.compiler.target :

<properties>
    <java.version>1.8</java.version>
    .... 
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

This way may make sense as the most of time, source and target version are the case (but it is not a standard way).


If you develop a Spring Boot application, you can choose the one or the other.
Otherwise, only the second should be used.

davidxxx
  • 115,998
  • 20
  • 192
  • 199