How do I specify the Java VM which should be used to build the release during mvn unleash:perform?

80 Views Asked by At

I get build errors when using mvn unleash:perform because it tries to use the default Java VM to build the release instead of the one pointed to with JAVA_HOME or the one which was used to start the maven-unleash-plugin.

With -Dunleash.releaseArgs="--debug=true" -X, I can see that the outer Maven uses Java 11 and the inner uses 8.

I tried to fix this with:

mvn unleash:perform -Dunleash.releaseEnvironment="JAVA_HOME=$JAVA_HOME" -X |& tee mvn.log

but that leads to an NPE:

Caused by: java.lang.NullPointerException
    at com.itemis.maven.plugins.unleash.steps.actions.BuildProject.setupInvocationRequest (BuildProject.java:123)
    at com.itemis.maven.plugins.unleash.steps.actions.BuildProject.execute (BuildProject.java:73)

Is changing the default VM in Windows my only option?

1

There are 1 best solutions below

0
Aaron Digulla On

In my case, the culprit was in .mavenrc (Linux) or %USERPROFILE%\mavenrc_pre.cmd (Windows, also check %USERPROFILE%\mavenrc_pre.bat). There, JAVA_HOME was hardcoded to some specific path.

The fix is to a) only set JAVA_HOME when it has no value and b) to display a warning (with path) when the variable is set. That way, people can't get confused by some silent behavior.

Solution in .mavenrc:

if [[ -z "$JAVA_HOME" ]]; then
    export JAVA_HOME=...
    echo "~/.mavenrc: Setting JAVA_HOME to $JAVA_HOME"
fi

For %USERPROFILE%\mavenrc_pre.cmd, use:

if "%JAVA_HOME%"=="" (
    set JAVA_HOME=...
    echo %USERPROFILE%\mavenrc_pre.cmd: Setting JAVA_HOME to %JAVA_HOME%
)