I have a weird problem with the maven-release-plugin, because it somehow uses another java version as the one which is used for the execution of maven. My initial situation is a bit strange. So we are using a CI/CD server where each module has its own jdk configuration. The CI/CD server has its JAVA_HOME environment variable set to Java 8, but we have multiple jdks installed, so that for example Java 11 can be used for the build process of a specific project. I checked the log output of the build process and noticed that this command is used for the maven execution and for switching between different jdks:
"/path/to/java" "-Dmaven.multiModuleProjectDirectory=/path/to/my-project" "-Dmaven.home=/path/to/maven" "-Dclassworlds.conf=/path/to/maven/bin/m2.conf" "-Dfile.encoding=UTF-8" -classpath "/path/to/maven/boot/plexus-classworlds-2.6.0.jar;/path/to/maven/boot/plexus-classworlds.license" org.codehaus.plexus.classworlds.launcher.Launcher clean package
So you can just swap /path/to/java and maven uses this jdk for the build process. If you check for example the file mvn.cmd, you will notice that this is the exact command maven uses internally to trigger the build process.
OK, now let me explain my problem. I am using a custom maven plugin where I inserted this command in the code:
getLog().info("java version: " + System.getProperty("java.runtime.version"));
Now, when I execute the above command with clean package at the end and with /path/to/java pointing to jdk11, the log output is: java version: 11.0.5+10-LTS. If I use release:prepare instead of clean package at the end (still with jdk11), the output is java version: 1.8.0_231-b11. So somehow the maven-release-plugin does not use the jdk which is used for the execution of maven, but uses JAVA_HOME instead. This only happens when using the release plugin. With the regular maven goals (clean, package, install, deploy) jdk11 is used, so in this case the one which is located at /path/to/java. Does anyone know why? And maybe someone has a solution how I can make the release plugin not to change the jdk (without changing JAVA_HOME).
I am already passing the path to my jdk via
-DjavaHome, but this does not do anything. I debugged the maven-release-plugin and noticed that in InvokerMavenExecutor the setting for javaHome is not passed to the executor. So I guess this is a bug in that plugin. I will create a bug ticket for this.