Repository navigation
fix: correct enforceBytecodeVersion excludes filtering - #990
Conversation
Invert the ArtifactMatcher result so excluded dependencies are skipped while include overrides remain eligible for bytecode checks. Add regression coverage for excludes with and without include overrides.
There was a problem hiding this comment.
Pull request overview
This PR fixes enforceBytecodeVersion dependency filtering so that dependencies matching configured excludes are actually skipped from bytecode analysis, while explicit includes continue to override broader excludes (aligning the rule’s filtering with ArtifactMatcher semantics and the documented behavior in the issue).
Changes:
- Invert
ArtifactMatcher.match(...)usage inEnforceBytecodeVersion#filterDependencies(...)so “matched” artifacts are excluded from analysis. - Add regression tests covering “excludes-only” filtering and “includes override excludes” behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| enforcer-rules/src/main/java/org/apache/maven/enforcer/rules/dependency/EnforceBytecodeVersion.java | Fixes filtering predicate so excluded dependencies are not analyzed. |
| enforcer-rules/src/test/java/org/apache/maven/enforcer/rules/dependency/EnforceBytecodeVersionTest.java | Adds targeted regression tests for the excludes/includes filtering behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Method method = EnforceBytecodeVersion.class.getDeclaredMethod("filterDependencies", List.class); | ||
| method.setAccessible(true); | ||
| return (List<Dependency>) method.invoke(rule, dependencies); | ||
| } |
There was a problem hiding this comment.
I agree with the diagnosis, but the fix should probably be to use an integration test rather than a unit test.
elharo
left a comment
There was a problem hiding this comment.
needs an integration test
Signed-off-by: w3lld1 <42353747+w3lld1@users.noreply.github.com>
|
Thanks — replaced the reflective unit coverage with the existing integration-test project in |
| if (includes != null || excludes != null) { | ||
| ArtifactMatcher artifactMatcher = new ArtifactMatcher(excludes, includes); | ||
| includeExcludeMatcher = d -> artifactMatcher.match(ArtifactUtils.toArtifact(d)); | ||
| includeExcludeMatcher = d -> !artifactMatcher.match(ArtifactUtils.toArtifact(d)); |
There was a problem hiding this comment.
It's not obvious from the code whether the not is needed or not. The word "filter" is ambiguous. It needs comments explaining what is expected that leaves no room for interpretation.
Avoiding lambdas would also make this clearer. As is I can't really tell what it's doing or what it's intended to do which is how we ended up with a bug in the first place.
| return new Dependency(new DefaultArtifact(groupId + ":" + artifactId + ":jar:1.0"), "compile"); | ||
| } | ||
|
|
||
| private static void setField(EnforceBytecodeVersion rule, String name, List<String> value) throws Exception { |
Signed-off-by: w3lld1 <42353747+w3lld1@users.noreply.github.com>
|
Thanks — addressed both follow-ups in
Fresh validation on the pushed commit:
|
elharo
left a comment
There was a problem hiding this comment.
It should be possible to test this with an integration test without using reflection
|
The current head already uses the existing invoker integration-test project without reflection. Commit |
|
@elharo please look again |
| <enforceBytecodeVersion> | ||
| <maxJdkVersion>1.5</maxJdkVersion> | ||
| <excludes> | ||
| <exclude>org.mindrot:jbcrypt:*:*</exclude> | ||
| <exclude>*:*</exclude> | ||
| </excludes> | ||
| <includes> | ||
| <include>com.google.code.findbugs:jsr305</include> | ||
| </includes> | ||
| </enforceBytecodeVersion> |
There was a problem hiding this comment.
We should not change this test .... it should be pass ... but it is wrong
org/mindrot/jbcrypt/BCrypt.class is compiled to JDK 1.5 so test will bass even wrong exclusion ...
we can change
<maxJdkVersion>1.5</maxJdkVersion>
to
<maxJdkVersion>1.4</maxJdkVersion>
|
Thanks — fixed the integration test in Fresh validation on the pushed commit:
|
Signed-off-by: w3lld1 <42353747+w3lld1@users.noreply.github.com>
241d311 to
4b0b810
Compare
The enforce-bytecode-version-excluded-deps project excluded every dependency with *:* at maxJdkVersion 1.4, so it passed just as well when filterDependencies() returned nothing at all. Narrow the exclude to commons-lang3, the only dependency targeting a JDK above the threshold, and keep jsr305 as a dependency that is really analysed and passes. Add enforce-bytecode-version-included-deps for the case where an include overrides a wide exclude - there the build has to fail on commons-lang3 alone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
@w3lld1 thanks for contribution, I have added next IT |
Following this checklist to help us incorporate your contribution quickly and easily:
mvn verifypassed as part of the command below.mvn -Prun-its verify.Summary
ArtifactMatcher.match()identifies dependencies that are excluded and not restored by an include override.enforceBytecodeVersionpreviously kept those matches for analysis, reversing the intended filtering behavior.This change negates that matcher result so excluded dependencies are skipped while explicit includes still override broad exclusions. It adds regression coverage for both excludes-only configuration and include overrides.
Verification
mvn -Prun-its verify— passed (151 plugin integration tests and 1 extension integration test; all reactor modules successful)mvn -pl enforcer-rules -am -Dtest=EnforceBytecodeVersionTest -Dsurefire.failIfNoSpecifiedTests=false test— passed (28 tests)git diff --check— passedFixes #985