stop IntelliJ IDEA to switch java language level every time the pom is reloaded (or change the default project language level)

Using IntelliJ 12, I have a java project and I use maven with a pom.xml. My project is using java8, but it seems the default project language level has been set to 6 while importing the project.

I can change the language level to 8.0 (F4 -> Modules -> Language level) however every time I edit my pom.xml the project level is switched back to "use project language level", and I have to edit this settings again and again.

Is there something I need to add to the pom.xml to set the default language level to 8.0?


As per Mark's comment, here is how to do it:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

A shorter version of vikingsteve's answer is:

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

I think this has to do with a conceptual conflict between the Maven compiler plugin and IntelliJ idea. Apparently the newer versions of the compiler plugin have a default level of 1.5 (see http://maven.apache.org/plugins/maven-compiler-plugin/). So if the compiler plugin is used at all in a project, and the compiler level is not explicitly set in the pom.xml, whenever the POM is re-processed the level will revert to the default.

So there is a conceptual conflict which is ignored by Intellij IDEA. The IDE still allows one to set the project and module settings, but provides no warning or feedback that this setting is controlled by pom.xml. Solutions would either be to explicitly allow overriding the POM compiler plugin setting (perhaps not wise because what then happens when you use maven on the command line), or to deactivate the controls in the IDE when this setting from the POM is in effect.

The solution at the present time is to set the desired compiler level in the compiler plugin in the pom, the re-import, rather than trying to set it in module settings.


I'm upgrading a project from JDK 8 to JDK 10+. I had the compiler properties specified correctly as follows:

<properties>
  <maven.compiler.source>10</maven.compiler.source>
  <maven.compiler.target>10</maven.compiler.target>
</properties>

However the Idea project would keep resetting the language level to 8.

Eventually I figured out that Idea's Maven import process was using JDK 8 to import the project which limited the language level to <= 8.

To fix I updated the 'JDK for importer' property under Settings -> Build, Execution, Deployment -> Build Tools -> Maven -> Importing to use JDK 11.

enter image description here


There are two ways of doing this, add either one of them in your pom.xml file:

First- Add Properties

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

second- Add Plugin

<plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
</plugin>

Let me know if it helps.