Repository navigation
Add ignoreOptionals option to bannedDependencies and requireReleaseDeps - #1078
slawekjaranowski wants to merge 2 commits into
Conversation
Closes apache#1077 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ascheman
left a comment
There was a problem hiding this comment.
LGTM — this closes a real gap, and thanks for handling the release-notes half separately.
I checked the thing that worried me, and it holds: the flag means the same thing in both modes. searchTransitive=false filters getDependencyArtifacts() with !(ignoreOptionals && a.isOptional()), and searchTransitive=true hands it to ResolverUtil.resolveTransitiveDependencies(…, excludeOptional, …), which filters project.getDependencies() with the identical predicate. Same scope — direct dependencies of the project — so there is no mode where the parameter surprises you. Default false keeps the 3.7.0 behaviour, which seems right.
I also like that banned-dependencies-fail was extended to assert that the transitive of an optional is banned. That pins the 3.7.0 behaviour which caused #1077, so a regression in either direction gets caught.
Verified locally on d4ec185: enforcer-rules green at 303 tests.
One non-blocking suggestion: the new banned-dependencies-ignore-optionals IT has no assertion. It contains only pom.xml — no verify.groovy (71 of the 117 IT projects have one, and its sibling banned-dependencies-fail does). It does discriminate on the feature, since a broken ignoreOptionals would ban menforcer138_io and fail the build; but it passes on "build succeeded", so it would also pass if the enforcer execution never ran at all. Two lines would close that:
def buildLog = new File( basedir, 'build.log' ).text
assert !buildLog.contains( 'banned via the exclude/include list' )And two cosmetic notes, take or leave:
- The rule parameter is
ignoreOptionalswhile the resolver method it delegates to calls the same conceptexcludeOptional— two names for one thing in the same package. - The site docs say "optional dependencies of the project (and their transitive dependencies)"; the PR description more precisely says direct optional dependencies. Adding "direct" would stop a reader expecting optionals to be skipped anywhere in the tree.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review!
|
Since 3.7.0,
bannedDependencies(andrequireReleaseDeps) also check direct optional dependenciesand their transitive dependencies. This restores the behavior lost in 3.3.0, but builds that passed
with 3.3.x–3.6.x can now fail, e.g. with an exclude like
*:*:*:jar:compile. There was no wayto opt out, because include patterns cannot match optional dependencies.
This PR adds a new
ignoreOptionalsparameter toBannedDependenciesBase, so it is availablefor both
bannedDependenciesandrequireReleaseDeps. Default isfalse, so the 3.7.0 behavior is kept.When
ignoreOptionalsistrue:searchTransitive=true(default): direct optional dependencies of the project are not collected,so they and their transitive dependencies are not checked
searchTransitive=false: direct optional dependencies are skippedCloses #1077
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following:
🤖 Generated with Claude Code