0

Context

I have a project in Java 8 that uses some libraries that don't exist on newer versions. I want to make a release using the Maven Release Plugin, with the command mvn release:prepare. I'm running this command inside IntelliJ, from the Execute Maven Goal button in Maven view.

Problem

When running mvn release:prepare, Maven correctly uses the Java 8 defined for my project. However, at some point, the goal tries to run another goal (mvn clean verify), which ends up using the system's default Java, which is Java 11. This last goal tries to compile the project but, since it is running with Java 11, it fails due to missing libraries.

Attempts

I've tried using the goal's javaHome parameter to specify the Java Home, like this:

mvn release:prepare -DjavaHome=C:\Users\X\.jdks\corretto-1.8.0_312

But nothing seems to change.

Question

In Maven Release Plugin's release:prepare goal, is there a way to specify the Java Home to be used in nested Maven invocations?

Flumen
  • 169
  • 2
  • 12
  • Usually, building with JDK 11 for Java 8 should work as well. Which errors do you get? – J Fabian Meier Nov 12 '21 at 08:04
  • @JFabianMeier I'm using some classes defined in `rt.jar`, which does not exist in Java 11. More specifically, classes from the package `javax.xml.bind`. – Flumen Nov 12 '21 at 16:36
  • Couldn't you follow this: https://stackoverflow.com/q/52502189/927493 ? – J Fabian Meier Nov 12 '21 at 18:22
  • @JFabianMeier I think it would work, but I consider it to be a workaround rather than the definitive solution. My project uses Java 8, which already has the needed libraries, so I shouldn't need to include those dependencies in my pom. Also, I am building it with Java 8, just as your link suggests. The problem is that a nested call to Maven runs with Java 11. – Flumen Nov 12 '21 at 21:51
  • Sooner or later you need to update the Java version anyway – J Fabian Meier Nov 13 '21 at 07:38
  • @JFabianMeier Yes, but that is not the point of the question. This is a problem that can arise at any moment. Let's say I update my project's Java version to 11, correcting the problem. Time passes and I decide to install Java 17 on my system. Also, suppose that I use some libraries from Java 11 that were removed in Java 17. The problem would happen again and I may not have the time nor interest to update my project's Java version. – Flumen Nov 13 '21 at 15:48
  • Yes, but I prefer to solve the concrete problem, not the hypothetical one. Sure, one day you'll want to change from Java 11 to Java 17, but at that time, the Maven Release Plugin might also be updated with new options, or it might even be replaced by something more fancy. – J Fabian Meier Nov 13 '21 at 20:13
  • Please update your question with full information about the problem you have (using rt.jar?) ... Have you defined `JAVA_HOME` vs. system defined java; Also using which version of maven-release-plugin etc. Maven version? If you need to to use javax.xml.bind you have to add other deps for JDK9+ there is no way around that... I would simply suggest to upgrade your build requirement to JDK11 (and produce a Java 8 output via `--release 8`) ...and very important. Don't run your release process inside IDEA intellij...use plain command line... – khmarbaise Nov 14 '21 at 09:17

0 Answers0