Andrii Radistao created MJDEPS-30:
-------------------------------------
Summary: jdeps plugin does not work when JAVA_HOME is not set
Key: MJDEPS-30
URL: https://issues.apache.org/jira/browse/MJDEPS-30
Project: Maven JDeps Plugin
Issue Type: Wish
Affects Versions: 3.1.2
Environment: Ubuntu 22.04.2 LTS
5.15.0-69-generic #76-Ubuntu SMP x86_64 GNU/Linux
Installed JDK:
Package: openjdk-11-jdk
Version: 11.0.18+10-0ubuntu1~22.04
openjdk 11.0.18 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Ubuntu-0ubuntu122.04, mixed
mode, sharing)
$JAVA_HOME is empty
Reporter: Andrii Radistao
When running command
{code:java}
mvn jdeps:jdkinternals{code}
(or any other maven workflow, which uses {{{}jdeps{}}})
on _any_ project without specified system environment variable {{JAVA_HOME}} -
the build fails with the error:
{quote}[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-jdeps-plugin:3.1.2:jdkinternals (default-cli) on
project cloud-backend-internal-client: Unable to find jdeps command: The
environment variable JAVA_HOME is not correctly set.
{quote}
all other maven tools ({{{}javac{}}}, {{{}jar{}}}, tests) and most of other
plugins work fine without {{JAVA_HOME}} specified
Note, that we use default java-11 installation on Debian (Ubuntu):
{code:java}
openjdk-11-jdk:amd64 11.0.18+10-0ubuntu1~22.04 amd64{code}
which doesn't set JAVA_HOME by default, but still has {{jdeps}} installed and
provided in the PATH (same as {{javac}} or {{jar}}):
{code:java}
$ command -v jdeps
/usr/bin/jdeps
$ jdeps --version
11.0.18
The issue happens because {{maven-jdeps-plugin:3.1.2}} resolves executable path
only by toolchain or JAVA_HOME, but ignores default {{PATH}} (like {{javac}} or
{{jar}} do) or JDK installation configuration:
[https://github.com/apache/maven-jdeps-plugin/blob/edcbab0c81a93338dab6fad479108e1102f86ca1/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java#L455-L465]
{code:java}
// ----------------------------------------------------------------------
// Try to find jdepsExe from JAVA_HOME environment variable
// ----------------------------------------------------------------------
if ( !jdepsExe.exists() || !jdepsExe.isFile() )
{
Properties env = CommandLineUtils.getSystemEnvVars();
String javaHome = env.getProperty( "JAVA_HOME" );
if ( StringUtils.isEmpty( javaHome ) )
{
throw new IOException( "The environment variable JAVA_HOME is not
correctly set." );
}
{code}
*Proposition:*
consider resolving {{jdeps}} executable location either by default {{PATH}} or
by {{SystemUtils#getJavaHome}}, like in [this
line|https://github.com/apache/maven-jdeps-plugin/blob/edcbab0c81a93338dab6fad479108e1102f86ca1/src/main/java/org/apache/maven/plugins/jdeps/AbstractJDepsMojo.java#L453-L453]:
{code:java}
jdepsExe = new File( SystemUtils.getJavaHome() + File.separator + ".." +
File.separator + "sh", jdepsCommand );{code}
*but* without {{".." + File.separator + "sh"}}
i tried and it proved to work:
{code:java}
new File( SystemUtils.getJavaHome() + File.separator + "bin", jdepsCommand
);{code}
I can supply a PR if this helps.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)