error running maven tool in intellij - "SDK 17 is not compatible with the source version 17"

Answered

I have a module that uses maven and java 17.   It compiles fine from the command line with mvn.   When I try to use the intellij Maven tool (on right sidebar) to run the install lifecycle, I get this error:

invalid target release: 17

Module my-module SDK 17 is not compatible with the source version 17.

Upgrade Module SDK in project settings to 17 or higher. Open project settings.

The module SDK is set to 17 (17.0.1) in the project settings.    Not sure what is wrong.  

Thanks

13 comments
Comment actions Permalink

What is the language level set for project and SDK set for the module? 

Please share the screenshot of your project and module settings.

0
Comment actions Permalink

Hello Konstantin,

The project SDK is 1.8 and the project language level is 8.   The module SDK is 17 and the module language level is 17 (preview).

0
Comment actions Permalink

Where does the Maven run? 8, or 17? Check the "Preferences | Build, Execution, Deployment | Build Tools | Maven | Runner" by default, project's JDK is chosen rather than module's one. 

1
Comment actions Permalink

Dear, Konstantin Annikov

I got the same issue. I don't understand your solution clearly. Can you have a better instruction?

0
Comment actions Permalink

Nguyen Duc Y

Go to File | Settings | Build, Execution, Deployment | Build Tools | Maven | Runner dialog. What is the version of the JRE selected there?

3
Comment actions Permalink

I had same issue in multimodule maven project with libs for spring-boot projects. Used spring-boot-dependencies 2.7.3, jdk-17.0.5 libs. I upgraded Idea to 2022.2.3 UE, sets version 17 in all above locations. Maven builds successfully several modules but fails in one with absolutely same settings with error: module [bla-bla-bla] SDK 17 is not compatible with the source version 17. Removing of one dependency org.apache.kafka:kafka-clients:2.5.1 helped me, error disappears

0
Comment actions Permalink

I had the same issue. I created Spring Boot 3.0 application with Java 17, opened it in Intellij IDEA and I couldn't build it because of almost the same error as OP mentioned. In project settings version 17 was chosen. And I don't have Kafka in pom.xml, like person above.

java: warning: source release 17 requires target release 17

Module demo SDK 16 is not compatible with the source version 17.

Upgrade Module SDK in project settings to 17 or higher. Open project settings.

It appears that even though I could choose version 17, the downloaded SDK was in version 16. I downloaded SDK 19, selected version 17 afterwards and project built successfully.

0
Comment actions Permalink

Please help what to do in this case 

0
Comment actions Permalink

Hello,

What source/target level is configured in your pom.xml file?

0
Comment actions Permalink

Hi Yaroslav. 

I have enconterd same error. My project Runner is below

module setting:

Run/debug configuration:

and my pom.xml

Whan can I do to cope this error?

 

0
Comment actions Permalink

Hello, 

I changed it like bellow and error gone away. 

0
Comment actions Permalink

Same initial settings with 225101403.

But solved the problem by setting Project Structure -> Modules -> Language level to 8 instead of removing those two maven.compiler lines.

0

Please sign in to leave a comment.