Explain Codes LogoExplain Codes Logo

Java version automatically changes to Java 1.5 after Maven update

java
maven-configuration
java-compiler-plugin
ide-settings
Nikita BarsukovbyNikita Barsukov·Dec 23, 2024
TLDR

Stacking up with the Java 1.5 era? Breakaway with an exclusive amendment in your pom.xml. Pile up your precise Java version in the same:

<properties> <maven.compiler.source>1.8</maven.compiler.source> <!-- Set my version, not your "version" --> <maven.compiler.target>1.8</maven.compiler.target> <!-- Hit the bullseye, right here --> </properties>

No more clunking with the rustic 1.5 version. Gear up with the glossy Java 1.8 using the above Maven-settings.

Advanced Maven Settings using Compiler Plugin

Aha! For those who fancy uptight precision in Maven configuration, load up your pom.xml with more plugin power.

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <!-- It's plugin time baby 🎸 --> <artifactId>maven-compiler-plugin</artifactId> <!-- The golden version always stays up-to-date, just like your ex--> <version>3.8.0</version> <configuration> <!-- Because compatibility is everything--> <source>1.8</source> <!-- Happy Source --> <target>1.8</target> <!-- Happy Target --> </configuration> </plugin> </plugins> </build>

Remember -- freshness matters! Keep the plugin version updated to maintain compatibility.

IDE Settings Sudden Overrides

Who doesn't like surprises from your Integrated Development Environment (IDEs) like Eclipse? (Using sarcasm font here 👈 😁)

  • Project facets: Go all clicky - project → properties → project facets → Java and fill it up with 1.8
  • Build path: Again click-clack your way to - project → build path → configure build path → libraries → JRE system library → set the exact same version.

Manage Environment and Dependencies

System libraries can go astray with their settings. Secure the setup:

  • Walk up to preferences/settings in your IDE, deck the list of installed JREs, make sure the IDE flaunts the matching JDK to what's in pom.xml.
  • Remember, Maven dependencies are like snacks, it can be old and stale. Refresh it with mvn -U clean install.

Java 9+ Specific Settings

For the future-proofed Java 9 or higher projects, morph your Maven config magic with updated maven.compiler.release property:

<properties> <maven.compiler.release>11</maven.compiler.release> <!-- For the dash to Future --> </properties>

That's the key to opening the door of Java Platform Module System (JPMS).

Considerate Post Maven Updateactivities

Post Maven update, revisit the pom.xml as if you are meeting your in-laws. Don't let the Java version switch its gear again.

  • Check for profiles that hold tight to a specific Java version.
  • Parent pom.xml is like a boss. Check if it meddles around.

In case nothing is working, meet old friends -- Maven community support or forums. If it is Eclipse acting up, it's time to either upgrade it or simply give it a fresh installation.

Keep an Eye on other Config Files

Like a hidden checklist, other background config files and system properties pitch in for this shift too.

  • .mvn/maven.config - Project-specific Maven configurations.
  • settings.xml - Located in ${maven.home}/conf, rules the Maven settings on a system-wide scale.

Absolutely Last Measures

When nothing works:

  • Uninstall the old JDK, install a fresh one (obviously the version you want!)
  • Give a final check to JAVA_HOME and PATH, make sure it's looking at the correct JDK.