rewrite
rewrite copied to clipboard
Gradle ChangeDependency behaves incorrectly, if new dependency exists
Gradle ChangeDependency shows following result, if new dependency was already defined:
rewriteRun(
spec -> spec.recipe(new ChangeDependency("commons-lang", "commons-lang", "org.apache.commons", "commons-lang3", "3.11.x", null, null)),
buildGradle(
"""
plugins {
id "java-library"
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.apache.commons:commons-lang3:2.6"
implementation group: "org.apache.commons", name: "commons-lang3", version: "2.6"
implementation "org.apache.commons:commons-lang3:3.11"
}
""",
"""
plugins {
id "java-library"
}
repositories {
mavenCentral()
}
dependencies {
implementation "commons-lang:commons-lang:2.6"
implementation group: "org.apache.commons", name: "commons-lang3", version: "2.6"
implementation "org.apache.commons:commons-lang3:3.11"
}
"""
Recipe replaced commons-lang:commons-lang with new groupId and artifactId, but kept the version from old dependency. Expected behavior will be just remove old dependency in this case:
implementation "org.apache.commons:commons-lang3:3.11"
Sounds like you're uncovering quite some edge cases over there! Appreciate you reporting these here and already tackling the Maven side of things in
- https://github.com/openrewrite/rewrite/pull/4515
PR was suggested: https://github.com/openrewrite/rewrite/pull/4523