-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recipe to search and provide a report of relocated dependencies #58
Comments
I like this suggestion, and would definitely help to get folks un-stuck from older dependencies. Thanks! |
Definitely. Awareness is the hardest part, and finding the newer coordinates is usually detective work openrewrite/rewrite-migrate-java#286 is one recent example of this and it took me a while to read their docs to find this out |
Had a quick look; we don't yet map I'll move this ticket to openrewrite/rewrite, since it looks to best fit in there given the search recipes we already have there. |
Had a first look for this one; attached a test of where we want to go package org.openrewrite.maven.cleanup;
import org.junit.jupiter.api.Test;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import static org.openrewrite.maven.Assertions.pomXml;
class RelocateArtifactsTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec.recipe(new RelocateArtifacts());
}
@Test
void shouldRelocateLatestVersion() {
rewriteRun(
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0</version>
<dependencies>
<!-- relocation in https://repo.maven.apache.org/maven2/ant/ant/1.7.0/ant-1.7.0.pom -->
<dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
</dependency>
<!-- relocation in https://repo.maven.apache.org/maven2/poi/poi/3.0.2-FINAL/poi-3.0.2-FINAL.pom -->
<dependency>
<groupId>poi</groupId>
<artifactId>poi</artifactId>
<version>3.0.2-FINAL</version>
</dependency>
</dependencies>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0</version>
<dependencies>
<!-- relocation in https://repo.maven.apache.org/maven2/ant/ant/1.7.0/ant-1.7.0.pom -->
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
</dependency>
<!-- relocation in https://repo.maven.apache.org/maven2/poi/poi/3.0.2-FINAL/poi-3.0.2-FINAL.pom -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.0.2-FINAL</version>
</dependency>
</dependencies>
</project>
"""
)
);
}
} |
Implementation is slightly more complicated since the meta data that we download does not show the version numbers that contain the relocation:
So then that complicates reuse if the discovery of newer versions as we usually do in |
So perhaps a better example is https://repo1.maven.org/maven2/mysql/mysql-connector-java/maven-metadata.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
<distributionManagement>
<relocation>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<message>MySQL Connector/J artifacts moved to reverse-DNS compliant Maven 2+ coordinates.</message>
</relocation>
</distributionManagement>
</project> |
There's also a separate plugin solely focused on migrating outdated groupIds; they maintain a list at: |
What problem are you trying to solve?
In Maven, there is a concept of relocation where library maintainers can publish a version of an artifact and provide additional metadata explaining the new coordinates where it was relocated to:
Example :
https://repo.maven.apache.org/maven2/ant/ant/1.7.0/ant-1.7.0.pom
In this case, ant moved from the group id
ant
->org.apache.ant
so users would normally need to change this manuallyDescribe the solution you'd like
I would like a search recipe to scan the direct dependencies in my pom file, detect and report the dependencies where this happened.
In the future, we can create a separate recipes to also do the change but that's outside of the scope of this recipe as that's likely more complex. An example is described here openrewrite/rewrite-migrate-java#289
Have you considered any alternatives or workarounds?
I am not aware of any alternative. Users need to watch out for this with every upgrade.
Many library maintainers do not include this metadata(or are aware of this feature), but that's a different problem
Additional context
These changes tend to puts users at risks. it would be ideal to identify these changes automatically as part of the build process/a search recipe
Maven guide : https://maven.apache.org/guides/mini/guide-relocation.html
The text was updated successfully, but these errors were encountered: