apache / apache/maven-shade-plugin
[MSHADE-398] MSHADE-185 IT failing if JAVA_HOME != JDK version running the test
- Dominant language
- Java
- Stars
- 188
- Forks
- 103
- Avg merge
- 16h 39m
- Merged PRs (30d)
- 4
Description
**[Alexander Kriegisch](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=kriegaex)** opened **[MSHADE-398](https://issues.apache.org/jira/browse/MSHADE-398?redirect=false)** and commented
Maven Invoker regression integration test (IT) `MSHADE-185` runs only on JDK <= 8. The CI builds on GitHub are fine, because they run on JDK 8 and also set `JAVA_HOME` accordingly. But on many systems, e.g. my developer workstation, `JAVA_HOME` points to a more recent JDK like 9, 11, 16. Those JDKs do not contain `tools.jar`, of course. So far, so good.
Now it is perfectly normal that a developer starts an IDE and from there loads her project and runs the Maven Shade build, selecting a different JDK to run Maven on, because for example they want to run all ITs. The same can happen in a console, if the developer starts Maven on a different Java executable than the one pointed to by `JAVA_HOME`. In both cases, the test fails, because the POM contains a system dependency on `tools.jar`.
First the Maven build started by Invoker fails:
```java
[ERROR] Failed to execute goal on project system-dep: Could not resolve dependencies for project test.shade:system-dep:jar:1.0.0-SNAPSHOT: Could not find artifact com.sun:tools:jar:1.6 at specified path c:\Program Files\Java\jdk-16\..\lib\tools.jar -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project system-dep: Could not resolve dependencies for project test.shade:system-dep:jar:1.0.0-SNAPSHOT: Could not find artifact com.sun:tools:jar:1.6 at specified path c:\Program Files\Java\jdk-16\..\lib\tools.jar
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies (LifecycleDependencyResolver.java:269)
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies (LifecycleDependencyResolver.java:147)
at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved (MojoExecutor.java:248)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:202)
```
Then later of course also the post-run verify step fails, because no dependency-reduced POM was created due to the fact that the build failed quickly:
```java
Running post-build script: C:\Users\alexa\Documents\java-src\maven-shade-plugin\target\it\MSHADE-185\verify.groovy
Assertion failed:
assert pomFile.isFile()
| |
| false
C:\Users\alexa\Documents\java-src\maven-shade-plugin\target\it\MSHADE-185\dependency-reduced-pom.xml
```
The solution would be to make sure that Invoker sets JAVA_HOME according to the JDK actually used for running the test. I have not investigated how to do that, but it should be possible somehow.
---
**Affects:** 3.2.4
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the MSHADE-185 Maven Invoker integration test and its POM, then inspect how the Invoker process selects JAVA_HOME when Maven runs under another JDK. Use verify.groovy and the reported dependency-reduced-pom.xml check to confirm the failure. Done means the test passes when JAVA_HOME points to a different JDK than the one running Maven.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100