RemoveDependency: how to delete multiple things with same groupId?
#4792
-
|
I have this recipe: However, when ran I only see one is processed (the first): Why are the others not processed? (FYI: the other recipe also matches in that same pom file) Oh, I also tried to extract them from the recipeList in their own recipe, and include that in the main list like this: But that didn't work out either (also only security is removed) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
|
Hi @svaningelgem ; I've quickly tried to replicate this issue with a unit test, but was not able to using this example: @Issue("https://github.com/openrewrite/rewrite/discussions/4792")
@Test
void removeTwoDependencies() {
rewriteRun(
spec -> spec.recipes(
new RemoveDependency("junit", "junit", null),
new RemoveDependency("com.google.guava", "guava", null)
),
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
"""
)
);
}Are you able to replicate this with a smaller sample perhaps? As an implementation detail: the dependency is removed by calling out to a visitor to remove that specific tag: If that tag can then not be found, perhaps because another recipe modified it in some way, then it will not be removed as it fails to match (different identity). |
Beta Was this translation helpful? Give feedback.
-
|
That might be possible because I'm changing the groupId from |
Beta Was this translation helpful? Give feedback.
-
|
Hi 👋, I can help with this! To delete multiple dependencies with the same
|
Beta Was this translation helpful? Give feedback.
Also to note, the groupId and artifactId I believe support glob patterns, so you could just throw a
?(match single character only) or*(match all remaining characters) on the end of either value to get back down to a single recipe statement.