IntelliJ imports project from POM using wrong JDK version

We have a Maven-based Android build, and we just made the switch from JDK 6 to 7.

This is due to his share in IntelliJ issues. It happens that every time he detects changes in the POM and refins / updates the project, he returns to selecting the old "SDK module", which is configured to use Java 6:

enter image description here

Even if I manually remove these SDKs from the Platform Settings dialog box, they will again appear as β€œMaven Android API 19 Platform (N),” where N is the number used to disambiguate it from all the other (identical) SDKs.

I must mention that we indicate in POM that Java 7 is aimed. I tried to set both the language level of the compiler plugin and the maven.compiler.* (not sure if this is the same or not), with no luck:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> 

should IntelliJ choose this and always configure the project to use the Java 7 SDK? Did I miss something?

I noticed that the problem disappears when I delete links to the 1.6 SDK completely in IntelliJ. Not surprisingly, I think, but also not viable, as I have other projects that still rely on having the Java 6 SDK.

+5
source share
2 answers

I ran into very similar problems with Maven projects that I created using IntelliJ (version 14.x in my case). I configured IntelliJ to use JDK 8 in the project settings, but the IDE continued to highlight problems in my code (for example, complaining about using @Override ).

It turned out that the Maven settings take precedence here, which in my case was JDK 1.5 by default (hence the IDE red lines). Changing the settings here fixes the problem, but only temporarily, because they go back whenever Maven projects are reimported or when IntelliJ restarts.

Permanent fix: explicitly declared by the JDK version in the maven pom file , as described in these articles.

stop IntelliJ IDEA to switch the Java level every time pom restarts (or changes the default language level) by @vikingsteve

IDEA: javac: source release 1.7 requires target version 1.7 from @bacchus

Here's what they said you need to add to the pom.xml file.

 <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> 

These settings are reflected in the Maven settings in the IDE and solve the problem for me.

+4
source

He will select the jdk that you select in the project structure, please change it there.

File> project structure> project setup> project> sdk project select 1.7.

If 1.7 is not, go to File> Project Structure> Platform Settings> SDKs addd 1.7 there.

0
source

Source: https://habr.com/ru/post/1201823/


All Articles