0

I'm working on a SpringBoot application with Java 11 that is built using Maven.

IntelliJ imports the project without any problems, but it shows me an error that for using eg. Map.of("A", "B") methods I need to raise the language level. Apparently IntelliJ doesn't detect the java version correctly that I'm using.

In my pom.xml I'm using the spring-boot-maven-plugin to build

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Other answers on SO (eg. IDEA: javac: source release 1.7 requires target release 1.7) tell me to set the "release" (or source/target) property for the maven-build-plugin but that is incompatible with the spring-boot-maven-plugin (ie. causes problems with dependencies etc.).

How can I make IntelliJ automatically recognize and set the Java language level to 11 without manually having to change it after every pom.xml reimport?

Kosi2801
  • 22,222
  • 13
  • 38
  • 45
  • as specified under https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html you can alternatively override the properties using ` 11 11 ` and that should help. Additionally I don't see why this is not a duplicate. – Naman Jan 21 '21 at 17:27
  • set java version in pom.xml. 11 if still see issue to go project structure -> Project -> change SDK – Satyendra Sharma Jan 21 '21 at 19:46
  • @Naman I did not realize that the other answers could solve the issue too since I was not using maven-compiler-plugin but spring-boot-maven-plugin. Furthermore for later Java Versions the maven-compiler-plugin supports the tag as replacement for and , which is also prefilled by the properts. That's why I assumed that my question/answer is likely a more current solution than the other ones you mentioned. – Kosi2801 Jan 22 '21 at 15:49

1 Answers1

0

By default IntelliJ (as of 2020.3) assumes Java language level 8 if not otherwise specified.

The spring-boot-maven-plugin respects the

<properties>
    <java.version>11</java.version>
</properties>

setting and adjusts the maven-compiler-plugin properties (release, source, target) accordingly, that are respected by IntelliJ for setting the Java language level on the project.

Just add this property to the pom.xml and reload the the project (not refresh, that didn't work for me).

See also How to specify Java 11 version in Spring/Spring Boot pom.xml? for a more detailed explanation on how this works behind the scenes.

Kosi2801
  • 22,222
  • 13
  • 38
  • 45