Transitive Dependencies
It’s widely known that when adding a dependency to a Maven project, its own dependencies are added automatically. This is Maven’s transitive dependency mechanism.
After Adding Shade Plugin
Adding Shade plugin to pom.xml:
| |
Then a fat jar will be generated to the target dir, along with the original jar.
However, after mvn install, user can’t find this library’s transitive dependencies:
| |
Just one line of the library itself.
Debug and Fix
Look back into library’s source, a file named dependency‑reduced‑pom.xml was generated by Shade plugin. This POM is generated in order ro avoid bundling the shaded dependencies again. So mvn install uses dependency‑reduced‑pom.xml as POM.
A difference between the original pom.xml and the generated dependency‑reduced‑pom.xml is that <scope>provided</scope> is added to dependencies in dependency‑reduced‑pom.xml. That’s why transitive dependencies are missing.
The fix is easy, just disable the reduced pom:
| |
and delete the generated dependency‑reduced‑pom.xml in the source.