Skip to content
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

Remove Jakarta annotation dependency when moving to Jakarta packages #487

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/resources/META-INF/rewrite/jakarta-ee-9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ recipeList:
- org.openrewrite.java.migrate.jakarta.UpdateApacheWSSecurityPackages
- org.openrewrite.java.migrate.javaee8
- org.openrewrite.java.migrate.jakarta.JavaxEEApiToJakarta
- org.openrewrite.java.migrate.jakarta.RemoveJakartaAnnotationDependency

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.jakarta.JavaxActivationMigrationToJakartaActivation
Expand Down Expand Up @@ -988,3 +990,15 @@ recipeList:
groupId: jakarta.platform
artifactId: "*"
newVersion: 9.0.0
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.migrate.jakarta.RemoveJakartaAnnotationDependency
displayName: Remove jakarta.annotation-api dependency if already manage by other dependency
description: This recipe mainly revert the jakarta.annotation-api added by org.openrewrite.java.migrate.javax.AddCommonAnnotationsDependencies
recipeList:
- org.openrewrite.java.dependencies.DependencyInsight:
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
groupIdPattern: jakarta.annotation
artifactIdPattern: jakarta.annotation-api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preconditions are the typical way to limit what files recipes operate on. That would look something like this

Suggested change
recipeList:
- org.openrewrite.java.dependencies.DependencyInsight:
groupIdPattern: jakarta.annotation
artifactIdPattern: jakarta.annotation-api
preconditions:
- org.openrewrite.java.dependencies.DependencyInsight:
groupIdPattern: jakarta.annotation
artifactIdPattern: jakarta.annotation-api
recipeList:

I'm not sure about the use of DependencyInsight here though, as we likely only want to remove the dependency if it's already available transitively. That might need some custom logic. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, not just found.
We need find in transitively "only", is this possible with DependencyInsight?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not right now; we do have an onlyDirect option on that recipe, but perhaps we'd need to add an onlyTransitive:
https://docs.openrewrite.org/recipes/maven/search/dependencyinsight#dependencies-in-use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, guess we can only postpone this PR until DependencyInsight support onlyTransitive? 😢

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly yes. Although that might not be too difficult as we already know the depth there, since we add that to the data table we produce.

Copy link
Contributor Author

@abccbaandy abccbaandy May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How?
Just like my comment 1. said, it's gone.

I can submit PR with the failed test if you want.

- org.openrewrite.java.dependencies.RemoveDependency:
groupId: jakarta.annotation
artifactId: jakarta.annotation-api
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,105 @@ public class TestApplication {
)
);
}

@Test
void projectWithSpringBoot3StarterWeb() {
rewriteRun(
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
spec -> spec.parser(JavaParser.fromJavaVersion().dependsOn(javaxServlet)),
mavenProject(
"Sample",
pomXml(
"""
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
""",
"""
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
"""
),
srcMainJava(
//language=java
java(
"""
import jakarta.servlet.A;
public class TestApplication {
}
"""
)
)
)
);
}
}