Main Tutorials

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 FileProject Structure..., ensures SDK and language level is set to Java 17.

project structure

IntelliJ IDE menu, clicks Build -> Rebuild Project.

rebuid project

References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments