java: warning: source release 17 requires target release 17
A Java project builds with Maven and runs on IntelliJ IDE but hits the following error message, and the IntelliJ IDE can’t compile the project.
java: warning: source release 17 requires target release 17
1. Solution
The above warning message tells you the Java project needs to compile and run with Java 17, but we are using an older Java version to compile it.
To fix it, ensure the maven-compiler-plugin
and IntelliJ IDE SDK and language level are set to Java 17.
1. maven-compiler-plugin
For Maven, declares the maven-compiler-plugin
plugin and ensure the source and target are set to Java 17.
pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<!-- 1.8, 1.10, 11, 12, 13-->
<source>17</source>
<target>17</target>
</configuration>
</plugin>
2. IntelliJ IDE
IntelliJ IDE menu, clicks File
– Project Structure...
, ensures SDK and language level is set to Java 17.
IntelliJ IDE menu, clicks Build
-> Rebuild Project
.
References
About Author
Comments
Subscribe
0 Comments