Skip to content

[MJDEPRSCAN-9] jdeprscan plugin does not work when JAVA_HOME is not set #44

@jira-importer

Description

@jira-importer

Andrii Radistao opened MJDEPRSCAN-9 and commented

When running command

 

mvn jdeprscan:jdeprscan

 

(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions