Java compiler version for Maven build of a Spring Boot product

It is practically always safe to use a newer version of the compiler than what the code was compiled with. The reverse is not always true.

In addition to bureaquete's suggestion to configure the Apache Maven Compiler Plugin, you may also be able to override the version in the properties section of your POM:

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

In order for this to work, you will need to have Java 7 installed and configured correctly.


You can specify the JDK for the Maven build by using the following plugin;

Apache Maven Compiler Plugin.

<project>
  ...
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.6.1</version>
          <configuration>
            <source>1.7</source>
            <target>1.7</target>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
  ...
</project>

Trying to compile Java1.7 code with JDK 1.6 would indeed cause issues.

Also you can use java.version property to specify your Java version, as described here, you can see the usage of maven-compiler-plugin on the spring-boot-parent pom.xml, here

Thanks to Brandon Mintern, and M.Deinum

Tags:

Spring Boot