Skip to content

Add support for Maven 4 PluginDescriptor.getRequiredJavaVersion() method #401

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

Merged
merged 2 commits into from
Jun 4, 2025

Conversation

gnodet
Copy link
Contributor

@gnodet gnodet commented May 14, 2025

Description

This PR enhances the PluginDescriptorHelper class to support the getRequiredJavaVersion() and setRequiredJavaVersion() methods directly on the PluginDescriptor class in Maven 4.

Implementation Details

The implementation:

  1. Uses reflection to check if the methods exist in the current Maven version
  2. Tries to use the direct methods first if available (Maven 4)
  3. Falls back to the existing wrapper approach if needed (Maven 3)

This approach ensures backward compatibility while taking advantage of the new methods in Maven 4.

Changes

  • Added static fields to hold method references using reflection
  • Enhanced the existing getRequiredJavaVersion() method to try the direct method first
  • Added a new setRequiredJavaVersion() method following the same pattern
  • Added comprehensive JavaDoc documentation for both methods

Pull Request opened by Augment Code with guidance from the PR author

This commit enhances the PluginDescriptorHelper class to support the getRequiredJavaVersion()
and setRequiredJavaVersion() methods directly on the PluginDescriptor class in Maven 4.

The implementation:
1. Uses reflection to check if the methods exist in the current Maven version
2. Tries to use the direct methods first if available (Maven 4)
3. Falls back to the existing wrapper approach if needed (Maven 3)

This approach ensures backward compatibility while taking advantage of the new methods in Maven 4.
Copy link
Member

Choose a reason for hiding this comment

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

How it will be used?

Why not direct use class from Maven core ... such master branch will be dedicated to Maven 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but I still think being able to build a maximum of projects targeting Maven 3 with Maven 4 is a good idea. We do want maximum compatibility when possible.
Also, if we target Maven 4, we should move to the new API, but that's more work imho.
So I'd rather to a micro release, and then start migrating this plugin to target Maven 4.

Copy link
Member

Choose a reason for hiding this comment

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

so should we do it in branch: maven-plugin-tools-3.x ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so should we do it in branch: maven-plugin-tools-3.x ?

Yes, I suppose. Not sure we need to do it now, unless someone wants to start the migration asap though.

@gnodet
Copy link
Contributor Author

gnodet commented May 27, 2025

There must be a missing file in this commit, as the helper class is not used at all.

@gnodet gnodet added the bug Something isn't working label Jun 4, 2025
@gnodet gnodet added this to the 4.0.0-beta-2 milestone Jun 4, 2025
@gnodet gnodet merged commit b939390 into master Jun 4, 2025
57 checks passed
@gnodet gnodet deleted the maven4-plugin-descriptor-java-version branch June 4, 2025 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants