apache / apache/maven-jdeprscan-plugin
[MJDEPRSCAN-9] jdeprscan plugin does not work when JAVA_HOME is not set
- Dominant language
- Java
- Stars
- 9
- Forks
- 11
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 1
Description
**[Andrii Radistao](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=radistao)** opened **[MJDEPRSCAN-9](https://issues.apache.org/jira/browse/MJDEPRSCAN-9?redirect=false)** and commented
When running command
```java
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):
```java
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{`}):
```java
$ 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:
https://github.com/apache/maven-jdeprscan-plugin/blob/36641ba0b618bf1e8bf84c51ac4f07e60cf0c01b/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java#L148-L154
```java
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](https://github.com/apache/maven-jdeprscan-plugin/blob/36641ba0b618bf1e8bf84c51ac4f07e60cf0c01b/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java#L142-L144):
```java
jdeprscanExe =
new File( SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", jdepsCommand );
```
**but** without `".." + File.separator + "sh"`
i tried and it proved to work:
```java
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](https://issues.apache.org/jira/browse/MJDEPS-30) jdeps plugin does not work when JAVA_HOME is not set
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java, especially the executable resolution around lines 142-154. Check how the plugin behaves when JAVA_HOME is unset, then verify that `mvn jdeprscan:jdeprscan` can locate `jdeprscan` from PATH or the Java installation and completes successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100