openrewrite / openrewrite/rewrite

Renaming coordinates without a newVersion carries the old version over to the new artifact

Open
#8,464 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
3.7k
Forks
571
Avg merge
13h 12m
Merged PRs (30d)
261

Description

What version of OpenRewrite are you using?

Latest main (reproduced at 560b40cc63).

What is the smallest, simplest way to reproduce the problem?

ChangeDependencyGroupIdAndArtifactId / ChangeManagedDependencyGroupIdAndArtifactId without a newVersion renames the coordinates of a <dependencyManagement> entry but keeps the version that belonged to the old coordinates:

rewriteRun(
  spec -> spec.recipe(new ChangeDependencyGroupIdAndArtifactId(
    "javax.servlet", "javax.servlet-api", "jakarta.servlet", "jakarta.servlet-api", null, null)),
  pomXml(
    """
      <project>
          <groupId>com.mycompany.app</groupId>
          <artifactId>my-app</artifactId>
          <version>1</version>
          <dependencyManagement>
              <dependencies>
                  <dependency>
                      <groupId>javax.servlet</groupId>
                      <artifactId>javax.servlet-api</artifactId>
                      <version>4.0.1</version>
                  </dependency>
              </dependencies>
          </dependencyManagement>
          <dependencies>
              <dependency>
                  <groupId>javax.servlet</groupId>
                  <artifactId>javax.servlet-api</artifactId>
              </dependency>
          </dependencies>
      </project>
      """
  )
);
What did you expect to see?

Either a version that exists for the new coordinates, or no change.

What did you see instead?

jakarta.servlet:jakarta.servlet-api:4.0.1, which does not exist:

<!--~~(jakarta.servlet:jakarta.servlet-api:4.0.1 failed. Unable to download POM: jakarta.servlet:jakarta.servlet-api:4.0.1. Tried repositories:
https://repo.maven.apache.org/maven2: HTTP 404)~~>-->
  • Version lines rarely carry over across a groupId change (javax.*jakarta.* is the common case), so carrying the old version over is usually wrong. Same applies to a <dependency> with an explicit <version>. Related to #8462, which covers the case where the version is dropped entirely rather than carried over.
Are you interested in contributing a fix?

Not immediately.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ChangeDependencyGroupIdAndArtifactId and ChangeManagedDependencyGroupIdAndArtifactId recipe entry points and reproduce the dependencyManagement example from the issue. Check the existing recipe tests around coordinate and version changes, then verify that renaming without newVersion does not carry an invalid old version into the new coordinates, including for an explicit dependency version.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.