Commit 30e77ff
authored
Fix RemoveDependency.unlessUsing for multi-module Maven projects (#183)
* Fix `RemoveDependency.unlessUsing` for multi-module Maven projects
`RemoveDependency` scans every source file and records whether `unlessUsing`
matched against the file's `JavaProject` marker. In a multi-module Maven
project the parent pom carries its own `JavaProject` distinct from the
children, so the parent module's accumulator entry never reflects type
usages found in child modules. The visitor would then strip the
`<dependency>` from the parent pom even though child modules in the same
reactor still relied on inheriting it.
Now the scanner additionally records the `MavenResolutionResult.id ->
JavaProject` mapping for every pom it visits. When the visitor is about to
remove a `<dependency>` from a pom, it walks that pom's descendant modules
via `MavenResolutionResult.getModules()` and preserves the declaration if
any descendant's `JavaProject` shows the type in use.
* Allow `RemoveDependency` to remove ancestor decl when descendants self-declare
The descendant-aware preservation introduced in the previous commit was
intentionally conservative: any descendant module whose Java sources used
the `unlessUsing` type blocked removal of the dep from an ancestor pom.
That over-preserves when a descendant module also declares the same
dependency directly in its own `<dependencies>` — in that case the
descendant is self-sufficient and the ancestor's declaration is dead
weight.
Refine the check: a descendant only blocks removal if it uses the type AND
does not declare the dependency itself. The self-declaration check looks
at the raw `requested` pom (as-written), not the resolved/inherited
dependency list, so a child that inherits the dep from the ancestor we
might modify still correctly blocks removal.1 parent 5559325 commit 30e77ff
2 files changed
Lines changed: 398 additions & 8 deletions
File tree
- src
- main/java/org/openrewrite/java/dependencies
- test/java/org/openrewrite/java/dependencies
Lines changed: 57 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
30 | | - | |
| 35 | + | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
| |||
68 | 73 | | |
69 | 74 | | |
70 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
71 | 81 | | |
72 | | - | |
73 | | - | |
| 82 | + | |
| 83 | + | |
74 | 84 | | |
75 | 85 | | |
76 | 86 | | |
77 | | - | |
| 87 | + | |
78 | 88 | | |
79 | 89 | | |
80 | 90 | | |
| |||
83 | 93 | | |
84 | 94 | | |
85 | 95 | | |
86 | | - | |
87 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
88 | 102 | | |
89 | 103 | | |
90 | 104 | | |
91 | 105 | | |
92 | 106 | | |
93 | 107 | | |
94 | | - | |
| 108 | + | |
95 | 109 | | |
96 | 110 | | |
97 | 111 | | |
| |||
103 | 117 | | |
104 | 118 | | |
105 | 119 | | |
106 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
107 | 125 | | |
108 | 126 | | |
109 | 127 | | |
| |||
118 | 136 | | |
119 | 137 | | |
120 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
121 | 170 | | |
0 commit comments