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

Image

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments