apache / apache/maven-shade-plugin
[MSHADE-267] Transitive dependencies of test dependencies included in shaded jar
- Dominant language
- Java
- Stars
- 188
- Forks
- 103
- Avg merge
- 16h 39m
- Merged PRs (30d)
- 4
Description
**[Jens Bannmann](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=jens.b)** opened **[MSHADE-267](https://issues.apache.org/jira/browse/MSHADE-267?redirect=false)** and commented
My project includes a `test` dependency to `org.testng:testng`, which has a bunch of `compile` and `test` dependencies:
```
com.github.elgashu:elgashu:jar:0.2-SNAPSHOT
+- org.testng:testng:jar:6.8:test
+- junit:junit:jar:4.10:compile
| \- org.hamcrest:hamcrest-core:jar:1.1:compile
+- org.beanshell:bsh:jar:2.0b4:test
+- com.beust:jcommander:jar:1.27:test
\- org.yaml:snakeyaml:jar:1.6:test
```
I use the Shade plugin to create a fat jar of my production code; I want neither my test code nor its dependencies to end up in that fat jar.
However, while the Shade plugin correctly excludes `org.testng:testng` itself (due to the `test` scope), its `compile` dependencies (`junit:junit:jar` and `org.hamcrest:hamcrest-core`) also end up in the shaded jar. This contradicts [Maven's rules for transitive dependency scoping](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope) which say that `compile` dependencies of `test` dependencies turn into `test` as well.
The workaround would be to explicitly exclude each of those transitive dependencies (and their transitive dependencies), but that effectively means manually tracking the dependency trees of all upstream dependencies, which IMO is not feasible.
---
**Affects:** 2.1, 3.1.0
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the shaded-jar build with a test-scoped org.testng:testng dependency and its transitive dependencies, then inspect how the Maven Shade Plugin collects dependency scopes. Done means compile dependencies inherited through test dependencies, such as junit and hamcrest-core, are absent from the production fat jar while production dependencies remain present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100