Commit 7e93ded
authored
Fix inverted exclusion comparison in
* Ignore spurious transitive exclusions when detecting redundant dependencies
A dependency's effective exclusions are resolved within the matched parent's
whole tree, so they can be polluted by exclusions other branches declare
against artifacts the coordinate could never bring on its own (e.g. an optional
dependency pruned elsewhere). Comparing these raw sets against a clean direct
declaration made the recipe keep genuinely redundant dependencies.
Filter each transitive's effective exclusions down to artifacts in the
coordinate's own dependency closure, dropping no-op exclusions before the
comparison. This only ever drops exclusions that change nothing, so it never
causes an unsafe removal.
* Simplify redundant-dependency exclusion filtering
Share the POM download/resolve path between resolveTransitivesFromPom and
dependencyClosure via resolvePom/withMavenCentral helpers, and hoist the
closure cache onto the Accumulator so it survives across source files in a
multi-module build.
* Compare declared exclusions, not effective ones, for redundant dependencies
Within a large dependency tree a coordinate's effective exclusions are corrupted
by dependency mediation: an artifact excluded on one path may already have been
pruned at a shared node, so it silently drops out of getEffectiveExclusions().
That inverted RemoveRedundantDependencies for e.g. spring-boot-starter-web ->
spring-boot-starter-tomcat -> tomcat-embed-websocket (openrewrite/rewrite#8336).
Compare each coordinate's declared (requested) exclusions instead, intersected
with its own clean closure to drop no-op exclusions, and apply the same relevant
-exclusion logic to the direct declaration being evaluated for removal.
Fixes openrewrite/rewrite#8336
* Resolve dependency closures lazily when comparing exclusions
Closure resolution was eager: every visited node carrying an inherited
exclusion triggered a POM download, resolve and compile-scope graph
resolution. Since ancestor exclusions are propagated into each child's
requested dependency, the "no exclusions" early-out rarely fired, so a
spring-boot-starter tree performed ~38 extra resolutions of which one was
ever consulted.
TransitiveDependency now carries declared exclusions, and the closure
intersection is deferred into isRedundant, where it runs only for a
coordinate that actually matched and only when the two declared sets
differ. Both sides share a single closure for that coordinate.
Also collapse the (repositories, downloader, ctx, cache) tuple into a
ClosureResolver, dedupe the two recursive dependency walks, key the cache
on GroupArtifactVersion so it is not repository-sensitive, and correct
the description and comments that described the abandoned mechanism.
* Drop redundant null check on non-null getRequested()
* Name the closure cache for what it holds
* Regenerate recipes.csv
* Keep dependencies whose declared exclusions differ
Comparing declared exclusions still required resolving each coordinate's
own dependency closure to discard exclusions it could never have honoured,
costing an isolated POM download and graph resolve per candidate.
Treat any difference in declared exclusions as "not redundant" instead.
This is strictly conservative: it can only keep a dependency that was
previously removed, never the reverse.
The cost is that a transitive which merely inherited an unrelated exclusion
from an ancestor no longer compares equal to a direct declaration carrying
none, so jakarta.ws.rs-api is now kept rather than removed. That test is
retained, inverted, to document the limitation.
* Regenerate recipes.csvRemoveRedundantDependencies (#191)1 parent 05c32f7 commit 7e93ded
3 files changed
Lines changed: 290 additions & 31 deletions
File tree
- src
- main
- java/org/openrewrite/java/dependencies
- resources/META-INF/rewrite
- test/java/org/openrewrite/java/dependencies
Lines changed: 24 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
148 | 149 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | 150 | | |
157 | | - | |
158 | | - | |
| 151 | + | |
| 152 | + | |
159 | 153 | | |
160 | | - | |
161 | 154 | | |
162 | 155 | | |
163 | 156 | | |
164 | | - | |
| 157 | + | |
165 | 158 | | |
166 | 159 | | |
167 | 160 | | |
| |||
182 | 175 | | |
183 | 176 | | |
184 | 177 | | |
185 | | - | |
| 178 | + | |
186 | 179 | | |
187 | 180 | | |
188 | 181 | | |
| |||
191 | 184 | | |
192 | 185 | | |
193 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
194 | 204 | | |
195 | 205 | | |
196 | 206 | | |
| |||
278 | 288 | | |
279 | 289 | | |
280 | 290 | | |
281 | | - | |
| 291 | + | |
282 | 292 | | |
283 | 293 | | |
284 | 294 | | |
| |||
0 commit comments