apache / apache/maven-dependency-plugin
Option to only allow explicit dependencies in `unpack` goal
- Dominant language
- Java
- Stars
- 175
- Forks
- 196
- Avg merge
- 19h 30m
- Merged PRs (30d)
- 5
Description
### New feature, improvement proposal
I've noticed a pervasive negative behavior throughout larger multi-module Maven projects for years now, and it has to do with the `unpack` goal.
Our developers tend to find this:
```xml
maven-dependency-plugin
generate-sources
unpack
mega.corp
some-module
1.0.0
resources
zip
```
more intuitive than (and therefore preferable to):
```xml
maven-dependency-plugin
generate-sources
unpack-dependencies
mega.corp
some-module
resources
zip
```
And I don't blame them:
1. It feels more "exact", since there is no chance of including more artifacts than intended. An `` (or even just ``) is guaranteed to only target 1 artifact.
2. The elements are more "familiar", since it uses the exact same XML elements as a regular ``.
3. `unpack` actually _fails_ when the artifact is not found, whereas `unpack-dependencies` simply continues silently while doing nothing, leading to harder to diagnose failures in later steps.
4. `unpack` works even if the `` (or ``) entries are _not_ defined as ``, so in the minds of our developers, there is no need to define the artifacts as ``. This keeps the POM-file nice and short, which is good, right? [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) principles etc.
I know that in this example, point 3 can be somewhat worked around by using ``+``+`` instead of ``+``, but you'd only know this by reading the plugin documentation. And like I said: intuitiveness.
But my major problem is point 4: **`unpack` works even if the `` entries are _not_ defined as ``**.
## Problem
I know this is by design and perfectly valid, but it has some very nasty side-effects. Primarily that `` are invisible to both the Maven reactor and the `maven-dependency-plugin` itself! This means that the artifacts will _not_ be detected by `dependency:tree`, nor by `dependency:go-offline`, nor by SBOM generators such as CycloneDX.
And in a multi-module Maven build where `` can refer to artifacts from different modules in the same tree, the Maven reactor also doesn't detect `` as inter-module dependencies. So they will _not_ be taken into account when determining the reactor build order. This issue is exacerbated when using multi-threaded builds such as when using the Maven Daemon, which can lead to sporadic build failures since the order isn't deterministic.
## Request
Either: Have all `` as defined in the `unpack` execution configuration automatically appended to the detected dependencies list. I think this would need to happen _very_ early in the Maven project discovery cycle for the reactor to be able to use these extra entries when determining project build order. This might prove to be very difficult to implement, and would entail breaking change behavior.
Or: Provide some way to force all `` to be explicitly defined as `` as well. Perhaps a `` boolean parameter can be added, which we can set in our parent POMs.
Or: Create a `maven-enforcer-plugin` rule that checks whether all `` (and ``) entries are actually present in the dependencies of the project. Perhaps augmented by some coordinate exclusion logic for edge cases.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the unpack goal and the Maven project discovery cycle, with dependency:tree, dependency:go-offline, SBOM generation, and reactor build ordering as affected entry points. Determine whether explicit artifactItems can be enforced or surfaced as dependencies, then verify that missing declarations are detected and reactor ordering remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100