Skip to content

Conversation

@timtebeek
Copy link
Member

@timtebeek timtebeek commented Dec 11, 2025

@timtebeek
Copy link
Member Author

@BoykoAlex a quick headsup that for some reason I'm not yet seeing the effects you were after for Gradle. Just in case you run into it there as well.

@BoykoAlex
Copy link

Hmm... if there is a quick unit test you could drop in rewrite-gradle as a PR i could have a look at this issue...
(There is a test I added for Gradle but it is probably not covering everything)

@timtebeek
Copy link
Member Author

Sure; in rewite-gradle that would be

    @Test
    void noDuplicateJacksonDatabindDependenciesInGradle() {
        rewriteRun(
          spec -> spec.beforeRecipe(withToolingApi())
            .recipes(
              new ChangeDependency(
                "com.fasterxml.jackson.core",
                "jackson-databind",
                "tools.jackson.core",
                null,
                "3.0.x",
                null,
                null,
                null
              ),
              new ChangeDependency(
                "com.fasterxml.jackson.datatype",
                "jackson-datatype-jsr310",
                "tools.jackson.core",
                "jackson-databind",
                "3.0.x",
                null,
                null,
                null
              )
            ),
          buildGradle(
            //language=gradle
            """
              plugins {
                  id("java-library")
              }
              repositories {
                  mavenCentral()
              }
              dependencies {
                  implementation("com.fasterxml.jackson.core:jackson-databind:2.19.0")
                  implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.19.0")
              }
              """,
            spec -> spec.after(buildGradle ->
              assertThat(buildGradle)
                .doesNotContain("jackson-datatype")
                .containsOnlyOnce("jackson-databind")
                .actual())
          )
        );
    }

Which fails with

java.lang.AssertionError: 
Expecting actual:
  "jackson-databind"
to appear only once in:
  "plugins {
    id("java-library")
}
repositories {
    mavenCentral()
}
dependencies {
    implementation("tools.jackson.core:jackson-databind:3.0.3")
    implementation("tools.jackson.core:jackson-databind:3.0.3")
}"
but it appeared 2 times 

@BoykoAlex
Copy link

BoykoAlex commented Dec 12, 2025

This helps:

However, I'm somewhat uncomfortable about computing resolvedVersion for every config... wonder if this needed at all. Wonder what would be the argument against keeping one cached resolvedVersion for all configs...

@timtebeek timtebeek marked this pull request as ready for review January 2, 2026 20:53
@timtebeek
Copy link
Member Author

Great to see this simplification; thanks again @BoykoAlex ! And best wishes for the new year. :)

@timtebeek timtebeek merged commit 3fd9a65 into main Jan 2, 2026
2 checks passed
@timtebeek timtebeek deleted the simplify-change-dependency-duplicates branch January 2, 2026 21:06
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Jan 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants