Skip to content

Feat: Resolver 2.x update policy control via CLI - #11948

Merged
cstamas merged 9 commits into
apache:maven-3.10.xfrom
cstamas:maven-3.10.x-am-policy-cli
Apr 20, 2026
Merged

cstamas merged 9 commits into
apache:maven-3.10.xfrom
cstamas:maven-3.10.x-am-policy-cli

Conversation

@cstamas

@cstamas cstamas commented Apr 14, 2026 •

Copy link
Copy Markdown
Member

Resolver 2.x supports split policies for artifacts and metadata. Introduce 4 new CLI options, that if used, renders old "all" options ignored (-U and -nsu). New options are:

  • -UA similar to existing -U but forces only artifact updates (resolves cached 404)
  • -UM similar to existing -U but forces only metadata updates (updates ranges and snapshots)
  • two long opts (--artifacts-update-policy=<policy> and --metadata-update-policy=<policy>) where user can explicitly fine tune override policies for artifacts and metadata.

If any of these 4 above are set, the old -U is ignored, and if any of -UA or -UM is set, the long counterpart is ignored.

Fixes #11918


Explanation: currently Maven had two update policy altering CLI options, -U and -nsu, and former set global session policy to "always" and latter to "never". Since Resolver 2.x update policies for artifacts and metadata are split and are handled as such.

Why it matters:

  • plugin prefix resolution happens via metadata -- "always" policy will refetch only metadata
  • snapshot resolution happens via metadata -- "always" makes sure any new ones are discovered
  • "remembered" 404 for missing artifact happens via artifacts

Before, when user issued -U he triggered all these above (forced refresh). Now, while -U still works, first two can be triggered with --metadata-update-policy=always (or suppress with never), and last one can be triggered with --artifact-update-policy=always without affecting the others (ie. discovery of new snapshots).

Resolver 2.x supports split policies for artifacts and metadata.
Introduce 2 new CLI options, that if used, renders old "all"
options ignored (-U and -nsu).
@cstamas cstamas added this to the 3.10.0 milestone Apr 14, 2026
@cstamas cstamas self-assigned this Apr 14, 2026
@cstamas cstamas added the enhancement New feature or request label Apr 14, 2026
@cstamas cstamas linked an issue Apr 14, 2026 that may be closed by this pull request
@cstamas
cstamas marked this pull request as ready for review April 14, 2026 09:56
Comment on lines +114 to +116
public static final String ARTIFACTS_UPDATE_POLICY = "artifacts-update-policy";

public static final String METADATA_UPDATE_POLICY = "metadata-update-policy";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about short version of options?

@cstamas cstamas Apr 17, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wanted an option like -U is but more versatile:

  • -mup would work like -U (set always for metadata)
  • but optionally, user could set actual policy -mup never or -mup always

But the problem with optional support in Commons CLI, is that it does not work like? Or at least I could not make it work, ie CLI like this mvn -mup clean would assume "clean" is a policy and it would explode (unknown policy "clean").

So, I ended up with long options with mandatory param that is nice and explicit --metadata-update-policy=never, and on CLI this is also clear mvn --metadata-update-policy=never clean and it is perfectly clear what is written here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Solved; introduced -UA and -UM that is like "half of" -U 😄 And the other two long opts allow user to fine tune policies, ie. use "never" policy on thing he wants.

@cstamas cstamas changed the title Support Resolver 2.x update policy control via CLI Feat: Resolver 2.x update policy control via CLI Apr 20, 2026
@cstamas
cstamas requested a review from kwin April 20, 2026 16:49
@cstamas
cstamas merged commit cf4ec75 into apache:maven-3.10.x Apr 20, 2026
18 checks passed
@cstamas
cstamas deleted the maven-3.10.x-am-policy-cli branch April 20, 2026 19:08
gnodet added a commit to gnodet/maven that referenced this pull request Oct 19, 2026
- Add --UA / --update-artifacts and --UM / --update-metadata CLI flags to force artifact/metadata updates (always policy)
- Add --artifacts-update-policy and --metadata-update-policy options for fine-grained update control; supported values: always, daily, interval:N, never, and explicit (new, updates only if not already cached)
- Warn when new-style policies are mixed with legacy -U / -nsu flags
- New MavenExecutionRequest.setArtifactsUpdatePolicy() / setMetadataUpdatePolicy() API; DefaultRepositorySystemSessionFactory dispatches to new policies when set, falling back to existing -U / -nsu behavior
- Port of apache#11948 to maven-4.0.x
gnodet added a commit to gnodet/maven that referenced this pull request Oct 19, 2026
- Add --UA / --update-artifacts and --UM / --update-metadata CLI flags to force artifact/metadata updates (always policy)
- Add --artifacts-update-policy and --metadata-update-policy options for fine-grained update control; supported values: always, daily, interval:N, never, and explicit (new, updates only if not already cached)
- Warn when new-style policies are mixed with legacy -U / -nsu flags
- New MavenExecutionRequest.setArtifactsUpdatePolicy() / setMetadataUpdatePolicy() API; DefaultRepositorySystemSessionFactory dispatches to new policies when set, falling back to existing -U / -nsu behavior
- Fix jvm.config LF-only handling on Windows (mvn.cmd retry logic)
- Port of apache#11948 to master
gnodet added a commit that referenced this pull request Oct 19, 2026
- Add --UA / --update-artifacts and --UM / --update-metadata CLI flags to force artifact/metadata updates (always policy)
- Add --artifacts-update-policy and --metadata-update-policy options for fine-grained update control; supported values: always, daily, interval:N, never, and explicit (new, updates only if not already cached)
- Warn when new-style policies are mixed with legacy -U / -nsu flags
- New MavenExecutionRequest.setArtifactsUpdatePolicy() / setMetadataUpdatePolicy() API; DefaultRepositorySystemSessionFactory dispatches to new policies when set, falling back to existing -U / -nsu behavior
- Port of #11948 to maven-4.0.x
gnodet added a commit that referenced this pull request Oct 19, 2026
- Add --UA / --update-artifacts and --UM / --update-metadata CLI flags to force artifact/metadata updates (always policy)
- Add --artifacts-update-policy and --metadata-update-policy options for fine-grained update control; supported values: always, daily, interval:N, never, and explicit (new, updates only if not already cached)
- Warn when new-style policies are mixed with legacy -U / -nsu flags
- New MavenExecutionRequest.setArtifactsUpdatePolicy() / setMetadataUpdatePolicy() API; DefaultRepositorySystemSessionFactory dispatches to new policies when set, falling back to existing -U / -nsu behavior
- Fix jvm.config LF-only handling on Windows (mvn.cmd retry logic)
- Port of #11948 to master
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

None yet

Development

Successfully merging this pull request may close these issues.

Resolver 2 supports split policies for artifacts and metadata

2 participants