Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Jenson3210
Copy link
Contributor

Summary

This PR extends Maven's UpgradeDependencyVersion recipe to automatically upgrade annotation processor versions in Maven's <annotationProcessorPaths> configuration, bringing Maven's behavior in line with how Gradle already handles annotation processor upgrades.

Problem

Previously, when using UpgradeDependencyVersion to upgrade dependencies like MapStruct, the recipe would upgrade:

  • Regular dependencies in <dependencies>
  • Plugin dependencies in <plugin><dependencies>
  • Gradle annotation processors

However, it would not upgrade Maven annotation processors defined in:

<annotationProcessorPaths>
  <path>
    <groupId>org.mapstruct</groupId>
    <artifactId>mapstruct-processor</artifactId>
    <version>1.4.1.Final</version>
  </path>
</annotationProcessorPaths>

This inconsistency meant that users had to manually update annotation processor versions in Maven projects, even when using automated dependency upgrade recipes.

Solution

This change treats Maven's <annotationProcessorPaths><path> elements similarly to plugin dependencies, ensuring they are upgraded alongside regular dependencies. The implementation:

  1. Adds detection for annotation processor path tags using a new ANNOTATION_PROCESSORS_PATH_MATCHER
  2. Reuses the existing upgrade logic (renamed from upgradePluginDependency to upgradeTag) for both plugin dependencies and annotation processor paths
  3. Properly handles version properties used in annotation processor declarations

Testing

Added comprehensive tests demonstrating:

  • Direct version upgrades in annotation processor paths
  • Version property resolution for annotation processors
  • Verification that Gradle variant of the recipe at the moment does the same thing.

Impact

This ensures consistent dependency management across build systems, eliminating the need for manual intervention when upgrading libraries that include annotation processors (like MapStruct, Lombok, etc.).

References

…sion for Maven similarly to how Gradle does it.
versionComparator, ctx);
}

public boolean isAnnotationProcessorPathTag(String groupId, String artifactId) {
Copy link
Contributor Author

@Jenson3210 Jenson3210 Aug 20, 2025

Choose a reason for hiding this comment

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

I deliberately did not add this to the MavenVisitor like the other methods, as i feel these pollute the MavenVisitor. We can add helper methods there for every kind of tag, but if there is no reuse needed, I feel this is not "big" enough to be part of the MavenVisitor to avoid ending up with a whole lot of different helper methods.

I did reuse isTag, making it protected accessible.

…sion for Maven similarly to how Gradle does it.
@timtebeek timtebeek changed the title Upgrade annotation processor versions in Maven when using UpgradeDependencyVersion Upgrade annotation processor versions in Maven when using UpgradeDependencyVersion Aug 21, 2025
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Approved from my side; let's get a final check just before we emrge.

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Aug 21, 2025
@timtebeek
Copy link
Member

Great! @Jenson3210 can you resolve the conflict and merge this PR? Then we can update our friends.

# Conflicts:
#	rewrite-maven/src/main/java/org/openrewrite/maven/UpgradeDependencyVersion.java
@Jenson3210 Jenson3210 merged commit a04973b into main Oct 15, 2025
2 checks passed
@Jenson3210 Jenson3210 deleted the upgrade-annotation-processor-versions branch October 15, 2025 15:40
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants