openrewrite / openrewrite/rewrite
UpgradeDependencyVersion does not correctly update BOM imports if they overlap
A pull request for this has already been merged.
- #6355 by @timtebeek — merged
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
What version of OpenRewrite are you using?
I am using
- rewrite-recipe-bom 3.18.0
How are you running OpenRewrite?
Writing my own recipes, but using JUnit tests to confirm the behavior observed "in the field".
What is the smallest, simplest way to reproduce the problem?
In this test we have two runs:
- In the first run we only upgrade
camunda-bomto 7.3.0 where it has no overlap withcamunda-engine-dmn-bom - In the second run we upgrade
camunda-bomto 7.20.0 where it has 4 entries in common withcamunda-engine-dmn-bom(camunda-engine-dmn, camunda-engine-feel-api, camunda-engine-feel-juel and camunda-engine-feel-scala).
@ParameterizedTest
@ValueSource(strings={"7.3.0","7.20.0"})
void sequentialRuns(final String targetVersion){
rewriteRun(
spec ->
spec.recipes(
new UpgradeDependencyVersion(
"org.camunda.bpm", "camunda-bom", targetVersion, null, null, null),
new UpgradeDependencyVersion(
"org.camunda.bpm.dmn", "camunda-engine-dmn-bom", "7.20.0", null, null, null)),
pomXml("""
<project>
<groupId>group.id</groupId>
<artifactId>artifactId</artifactId>
<version>1.0.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-bom</artifactId>
<version>7.2.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.camunda.bpm.dmn</groupId>
<artifactId>camunda-engine-dmn-bom</artifactId>
<version>7.10.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
""",
"""
<project>
<groupId>group.id</groupId>
<artifactId>artifactId</artifactId>
<version>1.0.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.camunda.bpm</groupId>
<artifactId>camunda-bom</artifactId>
<version>%s</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.camunda.bpm.dmn</groupId>
<artifactId>camunda-engine-dmn-bom</artifactId>
<version>7.20.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
""".formatted(targetVersion)));
}
What did you expect to see?
Both times both BOMs should be updated to version 7.20.0.
What did you see instead?
Only the first BOM listed in the pom.xml is updated. When swapped around, the other bom gets updated first; it seems to always be the first one from the top.
Setting the "overrideManagedVersion" flag does not change this behavior.
What else do you have to add?
I'm honestly not sure if this is a bug or not. While not understanding completely what's going on in the source code, I think it keeps track of which dependencies (directly or indirectly) got affected during the run already and does not touch a BOM if a dependency within has already been parsed.
While this might be inteded behavior, it does not state so in the documentation.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the shown parameterized JUnit test, sequentialRuns, and the UpgradeDependencyVersion recipe entry point. Reproduce both target-version runs against the pom.xml fixture, then confirm that both overlapping BOM imports are updated to the expected versions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100