Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java compiler version for Maven build of a Spring Boot product

Tags:

spring-boot

Here, it says that Spring Boot 1.5.2.RELEASE requires Java 7 or later; and Java 1.6 as the default compiler level.

So would this difference cause an issue?

like image 798
harry_no_spot Avatar asked Mar 15 '17 06:03

harry_no_spot


People also ask

Which Java compiler does Maven use?

The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.

Which Java version is used in Spring Boot?

System Requirements. Spring Boot 2.7. 5 requires Java 8 and is compatible up to and including Java 19.

What is Maven compiler version?

Apache Maven Compiler Plugin/ compiler:compile. | Last Published: 2022-03-08. Version: 3.10.1.

What is the minimum version of Java for Maven?

Lambda expressions need at minimum Java 8 to run. But by default Maven 3.8. 0 runs using Java version 1.6.


2 Answers

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.

like image 79
Brandon Avatar answered Oct 31 '22 16:10

Brandon


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

like image 23
buræquete Avatar answered Oct 31 '22 16:10

buræquete