9

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

This came with its share of IntelliJ problems though. What happens is that every time it detects a change in the POM, and reimports/refreshes the project, it returns to selecting the old "Module SDK", the one that's configured to use Java 6:

enter image description here

Even if I manually delete these SDKs from the "Platform Settings" dialog, they keep reappearing as "Maven Android API 19 Platform (N)" where N is the number used to disambiguate it from all the other (identical) SDKs.

I should mention that we do specify in the POM that Java 7 is targeted. I tried to set both the compiler plugin language level, and the maven.compiler.* properties (not sure if that accomplishes the same thing or not), without 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>

shouldn't IntelliJ pick that up and always configure the project to use a Java 7 SDK? Am I missing something?

I noticed that the problem disappears when I remove any references to 1.6 SDKs entirely in IntelliJ. Not surprising I guess, but also not viable since I have other projects that still rely on the presence of a Java 6 SDK.

Jonathan Drapeau
  • 2,610
  • 2
  • 26
  • 32
mxk
  • 43,056
  • 28
  • 105
  • 132

3 Answers3

5

I encountered a very similar issue with Maven projects I'd created using IntelliJ (version 14.x in my case). I'd configured IntelliJ to use JDK 8 in the Project Settings but the IDE continued to highlight issues in my code (e.g. complaining about the usage of @Override).

It turns out that the Maven Settings take precedence here, which in my case defaulted to JDK 1.5 (hence the IDE redlines). Changing the settings here does resolve the issue, but only temporarily because they revert back whenever the Maven projects are reimported, or when IntelliJ is restarted.

The permanent fix is to explicitly declared the JDK version in your Maven pom file, as explained in these items.

stop IntelliJ IDEA to switch java language level everytime the pom is reloaded (or change the default project language level) by @vikingsteve

IDEA: javac: source release 1.7 requires target release 1.7 by @bacchus

Here's what they've said you need to add to your 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 get reflected in the Maven Settings in the IDE and resolved the issue for me.

Community
  • 1
  • 1
Donnacha
  • 61
  • 1
  • 5
1

It will pick up the jdk that you choose in project structure please change it there.

File > project structure > project setting > project > project sdk choose 1.7.

If 1.7 is not present go to File > project structure > Platform setting > SDKs addd 1.7 there.

StackFlowed
  • 6,664
  • 1
  • 29
  • 45
  • 2
    well, I don't want to change it manually for every sub module every time I reload the POM... clearly that's a bug in IntelliJ then if this is necessary? – mxk Sep 04 '14 at 13:20
  • 1
    If you set it and the main module all the children will inherit that. – StackFlowed Sep 04 '14 at 13:20
  • 2
    That's not the problem. The problem is, all these things reset to Java 6 after reimporting. – mxk Sep 04 '14 at 13:30
  • Not a bug goto Intellj > preferences > complier > Java Complier and then set it to the version you want. I don't think the get reseted with and re import. – StackFlowed Sep 04 '14 at 19:36
  • I did that, even for every submodule specifically. No luck. – mxk Sep 06 '14 at 07:55
0

It's also important to note that you need to change the runner (jdk level) of your maven.

Maven > Runner > JRE

Ruelos Joel
  • 2,209
  • 3
  • 19
  • 33