rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Gradle ChangeDependency behaves incorrectly, if new dependency exists

Open ashakirin opened this issue 1 year ago • 2 comments

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"

ashakirin avatar Sep 24 '24 10:09 ashakirin

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

timtebeek avatar Sep 24 '24 12:09 timtebeek

PR was suggested: https://github.com/openrewrite/rewrite/pull/4523

ashakirin avatar Sep 25 '24 15:09 ashakirin