maven-shade-plugin
maven-shade-plugin copied to clipboard
[MSHADE-398] MSHADE-185 IT failing if JAVA_HOME != JDK version running the test
Alexander Kriegisch opened MSHADE-398 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:
[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:
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
Michael Osipov commented
Nice find. I don't know why this test requires tools.jar, but I would rather set Java 8 max for this test. Alternatively, this tests needs to use toolchains. WDYT?
Alexander Kriegisch commented
The test is Java 8 max. already, that is not the problem. The problem ist what I described. 😉
Michael Osipov commented
I read that but still, java.home isn't the same as JAVA_HOME. The https://github.com/apache/maven-shade-plugin/blob/master/src/it/projects/MSHADE-185/invoker.properties#L18|invoker.properties say Java 9+. I am confused.
Alexander Kriegisch commented
Attention, 9- is not the same as 9+. This is cryptic and undocumented, I also had to find out by experimenting. The documentation shows examples, but never explains their meanings, maybe assuming they would speak for themselves, which obviously they don't, if even a Maven guru like you does not know. Same goes for tests: no explanation.
Of course java.home is not the same as JAVA_HOME and can be overridden, but defaults to it. I recommend to simply give it a try, running the test, trying to reproduce what I described. I should not have to convince anyone, the facts speak for themselves.
Michael Osipov commented
It is documented: https://maven.apache.org/plugins/maven-invoker-plugin/examples/selector-conditions.html
Let me test too.
Michael Osipov commented
Generally, we don't recommend to run ITs in the IDE. I sometimes have failing tests in Eclipse which work in the shell. Can you exactly describe your command line environment for me how I can reproduce this?
Alexander Kriegisch commented
Ah yes, there it is. Cool, thanks. It is somewhat difficult to search on a page on my small mobile phone (Samsung S7), lots of scrolling. Not to mention editing typos on JIRA. Sorry, too lazy to get out of bed at 00.43. 😉
Michael Osipov commented
Take your time. All JAVA_HOME magic happens in the mvn booter script. Maybe Invoker can be smarter here.
Alexander Kriegisch commented
Like I said, I am not knowlegeable around Invoker, but pretty sure that there is a setting to tweak it the right way. As for a command line, I am lazy and simply added <invokerTest>setup-parent,MSHADE-185</invokerTest> to the Invoker config in the POM, then calling mvn verify. (Sorry for Jira striking through what it thinks is a closed issue reference.)
Update: I run the tests from within the IDE, yes, but still via Maven.