Skip to content

ResolverAdapter: a thin adapter over Resolver#1301

Merged
andrzejj0 merged 1 commit into
mojohaus:masterfrom
andrzejj0:resolver-adapter
Nov 3, 2025
Merged

ResolverAdapter: a thin adapter over Resolver#1301
andrzejj0 merged 1 commit into
mojohaus:masterfrom
andrzejj0:resolver-adapter

Conversation

@andrzejj0
Copy link
Copy Markdown
Contributor

@andrzejj0 andrzejj0 commented Nov 2, 2025

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors dependency version resolution and filtering across the versions-maven-plugin. The main changes include:

  • Introduces a new ResolverAdapter interface to abstract version resolution logic
  • Converts Property[] arrays to List<Property> throughout the codebase
  • Adds filtering capabilities to ArtifactVersions class via a new filter() method
  • Integrates rule-based version filtering into dependency update logging
  • Enhances RuleService with a getIgnoredVersions() method
  • Refactors DependencyUpdatesLoggingHelper from 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

    void resolveArtifact(Artifact artifact, boolean usePluginRepositories) throws ArtifactResolutionException;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread versions-common/src/main/java/org/codehaus/mojo/versions/api/ResolverAdapter.java Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

    void resolveArtifact(Artifact artifact, boolean usePluginRepositories) throws ArtifactResolutionException;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Member

@slachiewicz slachiewicz left a comment

Choose a reason for hiding this comment

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

Looks good to me. Maybe think if something will be soon exported in new Maven/Resolver to not duplicate here in future

@andrzejj0
Copy link
Copy Markdown
Contributor Author

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.
Regarding this plugin and this adapter -- I want a staged approach so that PRs can be reviewed easily.

@andrzejj0 andrzejj0 merged commit 95e3695 into mojohaus:master Nov 3, 2025
26 checks passed
@github-actions github-actions Bot added this to the 2.19.2 milestone Nov 3, 2025
Copilot AI pushed a commit that referenced this pull request Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants