Skip to content

Name a ChangeDependency instance by the coordinates it changes - #196

Merged
jkschneider merged 1 commit into
mainfrom
change-dependency-instance-name
Aug 25, 2026
Merged

Name a ChangeDependency instance by the coordinates it changes#196
jkschneider merged 1 commit into
mainfrom
change-dependency-instance-name

Conversation

@jkschneider

Copy link
Copy Markdown
Member

What's changed

ChangeDependency now implements getInstanceNameSuffix(), rendering the coordinates it acts on:

@Override
public String getInstanceNameSuffix() {
    return String.format("`%s:%s`", oldGroupId, oldArtifactId);
}

Why

The two recipes this one delegates to already do exactly this, byte for byte:

So the unified recipe was the only one of the three whose instance name did not name its
coordinates, and the same logical change read differently depending on which build tool it
dispatched to.

The default Recipe.getInstanceName() interpolates an option value only when exactly one
option is required. ChangeDependency requires two (oldGroupId, oldArtifactId), so it
fell through to the bare display name and every instance came out identical:

Change Gradle or Maven dependency
Change Gradle or Maven dependency
Change Gradle or Maven dependency

That is most visible in a composite that lists several. UpgradeSpringBoot_4_0 lists seven,
and they are the starter renames that make up much of a Boot 4 migration:

old new
spring-boot-starter-web spring-boot-starter-webmvc
spring-boot-starter-aop spring-boot-starter-aspectj
spring-boot-starter-oauth2-client spring-boot-starter-security-oauth2-client
spring-boot-starter-oauth2-resource-server spring-boot-starter-security-oauth2-resource-server
spring-boot-starter-oauth2-authorization-server spring-boot-starter-security-oauth2-authorization-server
spring-boot-starter-web-services spring-boot-starter-webservices
jobrunr-spring-boot-3-starter jobrunr-spring-boot-4-starter

Instance names also surface in SourcesFileResults and RecipeRunStats, where seven
identical rows are no more useful to someone reading the data table than to someone reading
the recipe list.

After:

Change Gradle or Maven dependency `org.springframework.boot:spring-boot-starter-web`
Change Gradle or Maven dependency `org.springframework.boot:spring-boot-starter-aop`
Change Gradle or Maven dependency `org.jobrunr:jobrunr-spring-boot-3-starter`

Note on the destination coordinate

This follows the two delegates and renders only the old coordinate, which is enough to tell
instances apart. Showing oldnew would read better still, but it would make this recipe
inconsistent with its delegates again, so it belongs in a change to all three rather than here.

Test plan

  • ChangeDependencyTest.instanceName asserts the rendered name for the
    spring-boot-starter-webspring-boot-starter-webmvc case
  • CI — this could not be run locally: ./gradlew test fails to compile
    UpgradeTransitiveDependencyVersion against the rewrite snapshot resolved in my
    environment, in a file this PR does not touch

Both recipes this one delegates to already do this. `ChangeDependencyGroupIdAndArtifactId`
and Gradle's `ChangeDependency` each render `` `oldGroupId:oldArtifactId` `` as their
instance name suffix, so the unified recipe was the only one of the three that fell back
to a bare display name.

The default `getInstanceName()` interpolates an option only when exactly one is required.
This recipe requires two, so every instance came out as "Change Gradle or Maven
dependency" regardless of what it changed. A composite that lists several of them — the
Spring Boot 4.0 migration lists seven — reads as the same line repeated, in the recipe
list and in the `SourcesFileResults` and `RecipeRunStats` data tables alike.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Aug 25, 2026
@jkschneider
jkschneider merged commit e11b466 into main Aug 25, 2026
1 check passed
@jkschneider
jkschneider deleted the change-dependency-instance-name branch August 25, 2026 09:22
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant