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?
The Compiler Plugin is used to compile the sources of your project. Since 3.0, the default compiler is javax.
System Requirements. Spring Boot 2.7. 5 requires Java 8 and is compatible up to and including Java 19.
Apache Maven Compiler Plugin/ compiler:compile. | Last Published: 2022-03-08. Version: 3.10.1.
Lambda expressions need at minimum Java 8 to run. But by default Maven 3.8. 0 runs using Java version 1.6.
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
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