Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Fixing the JDK Version Reset Triggered by POM Changes in IntelliJ IDEA

Tech Sep 22 1

Many developers notice that after modifying the pom.xml in an IntelliJ IDEA Maven project, the configured JDK version silently drops back to a lower default. Even though the IDE’s Settings and Project Structure dialogs show the correct version, Maven’s re-import wipes out those manual overrides. This forces repeated manual adjustments every time dependencies are added or the POM is edited.

Two reliable approaches exist to lock the compiler level permanently. The first works at the project level; the second is a global Maven configuration. They can be mixed or used independently, depending on whether all your projects share the same JDK baseline.

Project‑level fix via the compiler plugin

Embed a maven-compiler-plugin declaration directly in the project’s pom.xml. This tells Maven exactly which source and target versions too use, regardless of the IDE’s temporary settings.

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

Once this snippet is present, any Maven re-import honours the specified version. The approach works well when different projects require different JDKs, or when the code is shared with a team—everyone who pulls the repository automatically gets the correct compiler level without additional local configuraton.

Global Maven profile in settings.xml

A system‑wide profile in ~/.m2/settings.xml (or the IDE’s configured Maven settings file) applies the same JDK version to every project on that machine.

<profiles>
  <profile>
    <id>java-1.8</id>
    <activation>
      <activeByDefault>true</activeByDefault>
      <jdk>1.8</jdk>
    </activation>
    <properties>
      <maven.compiler.source>1.8</maven.compiler.source>
      <maven.compiler.target>1.8</maven.compiler.target>
      <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
  </profile>
</profiles>

This eliminates the need to repeat compiler settings in every project. However, it assumes a uniform JDK version across all your modules. A project that needs a newer version can still override the global default by adding the project‑level plugin configuration. Keep in mind that the global setting is machine‑specific; teammates will need to replicate the profile in their own Maven settings.

Both solutions stop the IDE from silently resetting the JDK version and save the repetitive effort of re‑configuring after every POM change.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.