Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,13 @@ public boolean isDependencyTag(String groupId, String artifactId) {
}
}
Dependency req = resolvedDependency.getRequested();
String reqGroup = req.getGroupId();
if ((reqGroup == null || reqGroup.equals(tag.getChildValue("groupId").orElse(null))) &&
req.getArtifactId().equals(tag.getChildValue("artifactId").orElse(null)) &&
ResolvedPom pom = getResolutionResult().getPom();
String reqGroup = pom.getValue(req.getGroupId());
String reqArtifact = pom.getValue(req.getArtifactId());
String tagGroupId = pom.getValue(tag.getChildValue("groupId").orElse(null));
String tagArtifactId = pom.getValue(tag.getChildValue("artifactId").orElse(null));
if ((reqGroup == null || reqGroup.equals(tagGroupId)) &&
reqArtifact.equals(tagArtifactId) &&
scope == tagScope) {
return true;
}
Expand Down Expand Up @@ -413,11 +417,14 @@ protected boolean isProperty(@Nullable String value) {
if (inClasspathOf != null && tagScope != inClasspathOf && !tagScope.isInClasspathOf(inClasspathOf)) {
return null;
}
ResolvedPom resolvedPom = getResolutionResult().getPom();
for (Map.Entry<Scope, List<ResolvedDependency>> scope : getResolutionResult().getDependencies().entrySet()) {
if (inClasspathOf == null || scope.getKey() == inClasspathOf || scope.getKey().isInClasspathOf(inClasspathOf)) {
for (ResolvedDependency d : scope.getValue()) {
if (tag.getChildValue("groupId").orElse(getResolutionResult().getPom().getGroupId()).equals(d.getGroupId()) &&
tag.getChildValue("artifactId").orElse(getResolutionResult().getPom().getArtifactId()).equals(d.getArtifactId())) {
String tagGroupId = resolvedPom.getValue(tag.getChildValue("groupId").orElse(null));
String tagArtifactId = resolvedPom.getValue(tag.getChildValue("artifactId").orElse(null));
if ((tagGroupId != null ? tagGroupId : resolvedPom.getGroupId()).equals(d.getGroupId()) &&
(tagArtifactId != null ? tagArtifactId : resolvedPom.getArtifactId()).equals(d.getArtifactId())) {
return d;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,62 @@ void removeDependencyWithTypeZip() {
)
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite/issues/4796")
void removeDependencyDefinedWithProperties() {
rewriteRun(
spec -> spec.recipe(new RemoveDependency("junit", "junit", null)),
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>

<properties>
<junit.groupId>junit</junit.groupId>
</properties>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<dependency>
<groupId>${junit.groupId}</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>

<properties>
<junit.groupId>junit</junit.groupId>
</properties>

<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
</dependencies>
</project>
"""
)
);
}
}
Loading