0

With Spring Boot (built with maven)
it is common to specify Java version in pom.xml as

    <properties>
        <java.version>17</java.version>
    </properties>

However from Spring Boot Maven Plugin Documentation
https://docs.spring.io/spring-boot/docs/2.7.x/maven-plugin/reference/htmlsingle/ has nothing related to Java compilation.

How java.version property is processed by Spring Boot build?

Paul Verest
  • 60,022
  • 51
  • 208
  • 332
  • 1
    https://stackoverflow.com/q/38882080/927493 – J Fabian Meier Mar 26 '23 at 16:19
  • @JFabianMeier that Q has extensive answer, however it does not answer this question How java.version property works? – Paul Verest Mar 26 '23 at 16:35
  • Spring Boot doesn't process the value, the compiler does. The question does not make any sense. – Bill Mair Mar 26 '23 at 16:39
  • 1
    The default java compiler level defined in Spring Boot Starter Parent is (still) the 1.8 The property overrides this default. In your example to 17. – Mar-Z Mar 26 '23 at 16:49
  • Starting with Spring Boot 3.0 the value is given with `17` (https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-parent/3.0.5/spring-boot-starter-parent-3.0.5.pom) – khmarbaise Mar 26 '23 at 18:42

1 Answers1

2

spring-boot-starter-parent uses java.version property to set value for both maven.compiler.source and maven.compiler.target

  <artifactId>spring-boot-starter-parent</artifactId>
  <packaging>pom</packaging>
  <name>spring-boot-starter-parent</name>
  <description>Parent pom providing dependency and plugin management for applications built with Maven</description>
  <properties>
    <java.version>17</java.version>
    <resource.delimiter>@</resource.delimiter>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties>

Sources

https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-starters/spring-boot-starter-parent/build.gradle#L20-L30

P.S. It is likely that Spring Boot 3.1 will switch to maven.compiler.release instead:
https://github.com/spring-projects/spring-boot/pull/34761

Paul Verest
  • 60,022
  • 51
  • 208
  • 332