Andrii Radistao opened MJDEPRSCAN-9 and commented
When running command
(or any other maven workflow, which uses jdeprscan)
on any project without specified system environment variable JAVA_HOME - the build fails with the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jdeprscan-plugin:3.0.0-alpha-1:jdeprscan (default-cli) on project cloud-backend-internal-client: Unable to find jdeprscan command: The environment variable JAVA_HOME is not correctly set. -> [Help 1]
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):
openjdk-11-jdk:amd64 11.0.18+10-0ubuntu1~22.04 amd64
which doesn't set JAVA_HOME by default, but still has jdeprscan installed and provided in the PATH (same as javac or {}jar{}):
$ command -v jdeprscan
/usr/bin/jdeprscan
$ jdeprscan --version
11.0.18
The issue happens because maven-jdeprscan-plugin:3.0.0-alpha-1 resolves executable path only by toolchain or JAVA_HOME, but ignores default PATH (like javac or jar do) or JDK installation configuration:
|
if ( !jdeprscanExe.exists() || !jdeprscanExe.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." ); |
if ( !jdeprscanExe.exists() || !jdeprscanExe.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." );
}
Proposition:
consider resolving jdeprscan executable location either by default PATH or by {}SystemUtils#getJavaHome{}, like in this line:
jdeprscanExe =
new File( SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", jdepsCommand );
but without ".." + File.separator + "sh"
i tried and it proved to work:
new File( SystemUtils.getJavaHome() + File.separator + "bin", jdepsCommand );
I can supply a PR if this helps.
Affects: 3.0.0-alpha-1
Issue Links:
- MJDEPS-30 jdeps plugin does not work when JAVA_HOME is not set
Andrii Radistao opened MJDEPRSCAN-9 and commented
When running command
(or any other maven workflow, which uses jdeprscan)
on any project without specified system environment variable
JAVA_HOME- the build fails with the error:all other maven tools (
{}javac{},{}jar{}, tests) and most of other plugins work fine withoutJAVA_HOMEspecifiedNote, that we use default java-11 installation on Debian (Ubuntu):
which doesn't set JAVA_HOME by default, but still has
jdeprscaninstalled and provided in the PATH (same asjavacor{}jar{}):The issue happens because
maven-jdeprscan-plugin:3.0.0-alpha-1resolves executable path only by toolchain or JAVA_HOME, but ignores defaultPATH(likejavacorjardo) or JDK installation configuration:maven-jdeprscan-plugin/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java
Lines 148 to 154 in 36641ba
Proposition:
consider resolving
jdeprscanexecutable location either by defaultPATHor by{}SystemUtils#getJavaHome{}, like in this line:but without
".." + File.separator + "sh"i tried and it proved to work:
I can supply a PR if this helps.
Affects: 3.0.0-alpha-1
Issue Links: