openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.23k stars 332 forks source link

`Change Gradle dependency artifact` breaks on platform dependency in `docs/spring-authorization-server-docs.gradle` #4090

Open knutwannheden opened 8 months ago

knutwannheden commented 8 months ago

Problem

Recipe can't handle Gradle dependency with exclude.

Example diff

From: docs/spring-authorization-server-docs.gradle

    }

dependencies {
-   implementation(platform("org.springframework.boot:spring-boot-dependencies:3.2.2")) {
+   {{80000000-0000-012e-0000-000000000000}}implementation(platform("org.springframework.boot:spring-boot-dependencies:3.2.2")) {
exclude group: "org.springframework.security", module: "spring-security-oauth2-authorization-server"
-   }
+   }{{80000000-0000-012e-0000-000000000000}}
implementation platform("org.springframework.security:spring-security-bom:6.1.0")
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"

Recipes in example diff:

Error messages:

org.openrewrite.gradle.ChangeDependencyArtifactId$1.lambda$visitMethodInvocation$0(ChangeDependencyArtifactId.java:102)
org.openrewrite.internal.ListUtils.map(ListUtils.java:176)
org.openrewrite.gradle.ChangeDependencyArtifactId$1.visitMethodInvocation(ChangeDependencyArtifactId.java:102)
org.openrewrite.gradle.ChangeDependencyArtifactId$1.visitMethodInvocation(ChangeDependencyArtifactId.java:85)
org.openrewrite.java.tree.J$MethodInvocation.acceptJava(J.java:3932)
org.openrewrite.java.tree.J.accept(J.java:59)
org.openrewrite.TreeVisitor.visit(TreeVisitor.java:283)
org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:366)
org.openrewrite.java.JavaVisitor.visitRightPadded(JavaVisitor.java:1375)
org.openrewrite.java.JavaVisitor.lambda$visitBlock$4(JavaVisitor.java:401)
org.openrewrite.internal.ListUtils.map(ListUtils.java:176)
org.openrewrite.java.JavaVisitor.visitBlock(JavaVisitor.java:400)
org.openrewrite.java.tree.J$Block.acceptJava(J.java:838)
org.openrewrite.java.tree.J.accept(J.java:59)
org.openrewrite.TreeVisitor.visit(TreeVisitor.java:283)
org.openrewrite.TreeVisitor.visitAndCast(TreeVisitor.java:366)
...

References:

shanman190 commented 8 months ago

So more specifically this is an exclude on a platform dependency only. It looks like the fix is to switch from ListUtils.map to ListUtils.mapFirst as is done with the other recipes that enact similar changes.