apache / apache/maven-enforcer

RequireUpperBoundDeps does not support includes with only groupId

Open Beginner friendly
#998 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
161
Forks
180
Avg merge
1d 20m
Merged PRs (30d)
8

Description

### Affected version

3.6.3

### Bug description

The docs for requireUpperBoundDeps state (emphasis mine):
> excludes - specify the dependencies that will be ignored. **The format is `groupId[:artifactId]`**
includes - specify the dependencies that will be checked. If not empty only these will be checked. **The format is `groupId[:artifactId]`**

... but in fact, the `artifactId` is *not* optional. We tried to narrow a plugin execution to only report on our team's first-party dependencies, by just including our own `groupId` in the execution, but when we tested it, it did not detect any of the known upper bound problems. We were only able to get it to work by specifying our `artifactId` values as well, which means we would have to specify every artifactId that we own. (This means, e.g., we can't reliably apply this enforcement in a central place without perpetually adjusting its includes every time we create a new shared component.)

I took a quick glance at RequireUpperBoundDeps.java and it appears to only check whether the include values *directly match* the visited dependencies, which is contrary to the docs (and prevents my use case).

The fix would be to make the artifactId truly optional when filtering dependencies for consideration, just like many of the other rules do: e.g., bannedDependencies works fine in this regard. Probably RequireUpperBoundDeps.java should be doing something like those rules: `Predicate shouldInclude = ArtifactUtils.prepareDependencyArtifactMatcher(includes)` instead of just a direct match comparison.

(My guess is that `excludes` probably has the same problem here, but I did not test it.)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in RequireUpperBoundDeps.java and compare its include and exclude filtering with the dependency rules that use ArtifactUtils.prepareDependencyArtifactMatcher. Add focused coverage for groupId-only includes, check whether excludes have the same behavior, and run the relevant Maven Enforcer tests to confirm known upper-bound problems are detected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.