ResolverAdapter: a thin adapter over Resolver#1301
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors dependency version resolution and filtering across the versions-maven-plugin. The main changes include:
- Introduces a new
ResolverAdapterinterface to abstract version resolution logic - Converts
Property[]arrays toList<Property>throughout the codebase - Adds filtering capabilities to
ArtifactVersionsclass via a newfilter()method - Integrates rule-based version filtering into dependency update logging
- Enhances
RuleServicewith agetIgnoredVersions()method - Refactors
DependencyUpdatesLoggingHelperfrom static utility to instance-based class
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
DependencyUpdatesLoggingHelper.java |
Converted from static utility to instance-based class with dependency injection; added rule-based filtering |
UpdatePropertyMojo.java |
Converted Property array to Collections.singletonList |
UpdatePropertiesMojo.java |
Changed Property[] field to List |
SetPropertyMojo.java |
Changed Property[] to List in local variables and method signatures |
DisplayPropertyUpdatesMojo.java |
Changed Property[] field to List |
DisplayExtensionUpdatesMojo.java |
Integrated new DependencyUpdatesLoggingHelper and ResolverAdapter; added rule-based filtering |
DisplayDependencyUpdatesMojo.java |
Integrated new DependencyUpdatesLoggingHelper and ResolverAdapter; refactored dependency resolution |
AbstractVersionsUpdaterMojo.java |
Changed serverId and rulesUri from private to protected |
AbstractPropertyUpdatesReport.java |
Changed Property[] to List; updated import for VersionPropertiesMapRequest |
PropertiesVersionsFileReader.java |
Refactored to return List instead of array; streamlined implementation |
RuleServiceUtils.java |
New utility class for filtering artifact versions based on rules |
RuleService.java |
Added getIgnoredVersions() method |
DefaultResolverAdapter.java |
New implementation of ResolverAdapter interface for version resolution |
VersionsHelper.java |
Extended ResolverAdapter interface; changed Property[] to List |
ResolverAdapter.java |
New interface abstracting version resolution operations |
PropertyVersionsBuilder.java |
Updated to use ResolverAdapter; added overloaded build() method |
PomHelper.java |
Updated method signatures to use ResolverAdapter instead of VersionsHelper |
IgnoreVersionHelper.java |
Refactored to use enum-based type matching; added overloaded isVersionIgnored() |
DefaultVersionsHelper.java |
Implements ResolverAdapter interface methods; updated return types to SortedMap |
ArtifactVersions.java |
Added filter() method for predicate-based version filtering |
| Test files | Updated to use List instead of arrays |
| Integration test files | New test for issue-1295 with version ranges |
Comments suppressed due to low confidence (1)
versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java:419
- This method overrides ResolverAdapter.resolveArtifact; it is advisable to add an Override annotation.
void resolveArtifact(Artifact artifact, boolean usePluginRepositories) throws ArtifactResolutionException;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8f24c75 to
2b72c45
Compare
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
versions-common/src/main/java/org/codehaus/mojo/versions/api/VersionsHelper.java:419
- This method overrides ResolverAdapter.resolveArtifact; it is advisable to add an Override annotation.
void resolveArtifact(Artifact artifact, boolean usePluginRepositories) throws ArtifactResolutionException;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
slachiewicz
left a comment
There was a problem hiding this comment.
Looks good to me. Maybe think if something will be soon exported in new Maven/Resolver to not duplicate here in future
I'm not aware of what's going to come to the actual Resolver, so I can't tell that. |
2b72c45 to
263d220
Compare
Over time, VersionsHelper has evolved into a behemoth with multiple, diverging responsibilities—a "helper" class performing various tasks for the plugin's mojos. Its broad scope has led to a tightly coupled and entangled architecture that is difficult to navigate and maintain. Several convenience methods, such as lookupDependenciesUpdates, perform similar but slightly different tasks, adding to the complexity.
One consequence of this design is inconsistency across mojos that operate in similar domains. For example, displayDependencyUpdates and useLatestVersions rely on different methods within VersionsHelper, each executing subtly different retrieval logic. In the case of the display mojo, filtering is applied twice: first within the helper (e.g., excluding snapshots), and then again in the mojo itself.
The ultimate goal is to clean up this architecture and potentially introduce a shared backend that can be used by plugins responsible for updating and displaying dependencies. Achieving this requires a simpler, more modular design.
This PR introduces a thin wrapper around Resolver, focused solely on retrieving available versions—essentially translating Resolver functionality into Maven terms. Once versions are retrieved, filtering can be handled cleanly via ArtifactVersions.
To demonstrate this approach, DisplayDependencyUpdates and DisplayExtensionUpdates have been refactored to use the new API.
Additionally, VersionsHelper has been extended to support the new API, allowing underlying components such as RuleService to work with both VersionsHelper and the new ResolverAdapter.
A minor improvement: PropertyBuilder now uses a collection for Properties, aligning the API more closely with future enhancements.