https://bugzilla.redhat.com/show_bug.cgi?id=2020478
Bug ID: 2020478
Summary: mvn overrides JAVA_HOME so compilation fails
Product: Fedora
Version: 35
Hardware: All
OS: Linux
Status: NEW
Component: maven
Severity: medium
Assignee: mizdebsk(a)redhat.com
Reporter: vk2bea+fedora(a)gmail.com
QA Contact: extras-qa(a)fedoraproject.org
CC: java-sig-commits(a)lists.fedoraproject.org,
mizdebsk(a)redhat.com, msrb(a)redhat.com
Target Milestone: ---
Classification: Fedora
Setting of JAVA_HOME is overwritten by mvn.
/usr/bin/mvn is a script that sources /etc/java/maven.conf which overrides
JAVA_HOME. If maven-openjdk11 is installed then this is Java 11, if
maven-openjdk17 is installed it is Java 17 regardless of the user's setting of
JAVA_HOME.
This means that the compilation of a Java source file with features
incompatible with the version set in /etc/java/maven.conf will fail.
e.g:
1. install maven-openjdk11
3. use 'alternatives' to set java to java 17 (JAVA_HOME set to
/usr/lib/jvm/java-17-openjdk-17.0.1.0.12-1.rolling.fc35.x86_64)
4. Attempt to use maven to compile Java that has Java 17 features
5. Compilation fails
If MAVEN_SKIP_RC environment variable is set then /etc/mavenrc, /etc/mavenrc
and "$HOME/.mavenrc" are ignored. This will mean that JAVA_HOME is not
overwritten but maven may then run with a (possible) incompatible version.
(setting JAVA_HOME in
"$HOME/.mavenrc" will also do this)
In /usr/bin/mvn, maven is run with the java specified in JAVACMD.
if [ -z "$JAVA_HOME" ] ; then
JAVACMD=`which java`
else
JAVACMD="$JAVA_HOME/bin/java"
fi
It looks to me that a better solution is to set JAVACMD to specific Java
version of the installed maven libraries (e.g. 11) and leave alone JAVA_HOME so
that the user java files are compiled as expected.
--
You are receiving this mail because:
You are on the CC list for the bug.
https://bugzilla.redhat.com/show_bug.cgi?id=2020478