rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Maven - Update the `scm` configuration to match the `origin` of the repository

Open yeikel opened this issue 6 months ago • 3 comments

What problem are you trying to solve?

Following a migration to a new git server, many of my projects now have outdated SCM configuration properties.

Although it is possible to update the SCM configuration manually or with a generic xml file, doing so at scale is not practical as each repository may have different inputs

We should have a recipe that detects the origin of the repository and fixes the scm as needed

What precondition(s) should be checked before applying this recipe?

The maven project has a scm configuration that does not match the server where the repository is

Describe the situation before applying the recipe

git remote get-url origin
https://new-server.example.com/org/repo.git

A pom file with the scm configuration set with a configuration that does not match the origin server

<scm>
        <url>https://old-server.example.com/org/repo</url>
        <connection>scm:git:https://old-server.example.com/org/repo.git</connection>
        <developerConnection>scm:git:[email protected]:org/repo.git</developerConnection>
    </scm>

Describe the situation after applying the recipe

The scm configuration is updated to match the origin

<scm>
        <url>https://new-server.example.com/org/repo</url>
        <connection>scm:git:https://new-server.example.com/org/repo.git</connection>
        <developerConnection>scm:git:[email protected]:org/repo.git</developerConnection>
    </scm>

yeikel avatar Jun 04 '25 13:06 yeikel

Hi @yeikel ; Seems like a good fit for a recipe indeed! We already have the GitProvenance marker: https://github.com/openrewrite/rewrite/blob/982ad13ca1282bc9831864670f8bb800454c8e04/rewrite-core/src/main/java/org/openrewrite/marker/GitProvenance.java#L52-L60

That ought to be available when you visit a pom file to make the necessary changes. Would you be open to working on this?

timtebeek avatar Jun 04 '25 17:06 timtebeek

Since there hasn't been a response yet, I'd be happy to pick this up.

e5LA avatar Jun 14 '25 20:06 e5LA

That'd be appreciated, thanks! Would make for a nice addition to org.openrewrite.maven.BestPractices https://github.com/openrewrite/rewrite/blob/846412f09c45ff4b7d7295df77fcbe28bf86927d/rewrite-maven/src/main/resources/META-INF/rewrite/maven.yml#L17-L28

timtebeek avatar Jun 14 '25 20:06 timtebeek