Skip to content

[MNG-8693] Avoid resolving unused plugins for direct goals - #12721

Open
goutamadwant wants to merge 2 commits into
apache:masterfrom
goutamadwant:MNG-8693-avoid-unused-plugin-resolution
Open

[MNG-8693] Avoid resolving unused plugins for direct goals#12721
goutamadwant wants to merge 2 commits into
apache:masterfrom
goutamadwant:MNG-8693-avoid-unused-plugin-resolution

Conversation

@goutamadwant

Copy link
Copy Markdown

Fixes #10128.

Summary

Direct CLI goals currently trigger missing-version resolution for every plugin in the project before Maven resolves the requested goal. Plugin version compatibility checks load plugin descriptors, which can download versionless build and managed plugins even when the goal does not use them.

This change:

  • skips project-wide plugin version resolution while calculating direct goal task segments;
  • limits project-wide resolution during execution planning to plans that contain lifecycle phases; and
  • resolves a missing version lazily when a project-declared plugin is actually considered during prefix resolution.

Lifecycle-phase plans continue to resolve missing plugin versions before lifecycle mapping. Direct goals continue to resolve the selected plugin through the existing descriptor path.

Tests

  • mvn -pl impl/maven-core -am -Dtest=DefaultPluginPrefixResolverTest,DefaultLifecycleExecutionPlanCalculatorTest -Dsurefire.failIfNoSpecifiedTests=false test
  • mvn -pl impl/maven-core -am test
  • mvn verify
  • Built the Maven distribution and ran help:help against an isolated project with versionless maven-release-plugin and maven-javadoc-plugin entries in pluginManagement. The command succeeds without resolving or downloading either unused plugin.
  • Attempted mvn -Prun-its install. Core IT reached 518 tests, with 494 passing and 23 skipped; MavenITmng4428FollowHttpRedirectTest.testitHttpsToHttps failed while retrieving an artifact through its local HTTPS redirect server under JDK 26. This test and failure path are unrelated to the changed plugin-resolution code.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Skip project-wide plugin version resolution for direct-goal-only plans while preserving it for lifecycle phases. Resolve versionless project prefix candidates lazily and add regression coverage for both paths.

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well-structured optimization that correctly defers plugin version resolution to the point of actual use (MNG-8693). The lazy resolution in DefaultPluginPrefixResolver is correctly placed inside existing error handling, and the conditional guard in DefaultLifecycleExecutionPlanCalculator properly limits bulk resolution to lifecycle-phase builds.

Two minor observations (non-blocking):

  1. Test coverage: The new DefaultLifecycleExecutionPlanCalculatorTest covers the negative case (GoalTask does not trigger resolveMissingPluginVersions). A complementary positive test verifying that a LifecycleTask does trigger resolution would strengthen coverage.

  2. Subtle behavioral difference: The new version request in DefaultPluginPrefixResolver includes .setPom(request.getPom()), which the previous bulk resolution in LifecyclePluginResolver did not pass. This gives the version resolver more context (pluginManagement declarations) and is arguably more correct, but it's a subtle difference worth noting.

The forked execution path correctly retains the resolveMissingPluginVersions call for forked projects, and error handling is maintained (lazy resolution falls inside the existing catch(Exception) block).

This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of gnodet

Add the complementary positive regression that lifecycle tasks continue to resolve missing project plugin versions before lifecycle mapping.
@goutamadwant

Copy link
Copy Markdown
Author

@gnodet Thanks for the review. I added the complementary lifecycle-task test to verify that project-wide plugin version resolution is still performed for lifecycle-phase plans.

I kept the POM on the lazy version request intentionally so the selected project plugin can reuse version information from the project or pluginManagement before falling back to repository resolution.

@gnodet gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well-structured optimization that correctly defers plugin version resolution to the point of actual use for direct CLI goals (MNG-8693). The lazy resolution in DefaultPluginPrefixResolver is properly placed inside existing error handling, the conditional guard in DefaultLifecycleExecutionPlanCalculator correctly limits bulk resolution to lifecycle-phase plans, and test coverage is solid.

Minor observations (non-blocking):

  • The new lazy version request passes setPom(request.getPom()) which the previous bulk resolution in LifecyclePluginResolver did not. This gives the version resolver more context (pluginManagement declarations) and is arguably more correct, but it is a subtle behavioral difference. The PR author acknowledged this as intentional.
  • plugin.setVersion() directly mutates the model Plugin object. This is consistent with what LifecyclePluginResolver.resolveMissingPluginVersions already does, so it is not a new concern.
  • The forked execution path at DefaultLifecycleExecutionPlanCalculator line 374 correctly retains the resolveMissingPluginVersions call for forked projects, ensuring no regression for mojos that fork lifecycle phases.
  • Test coverage is comprehensive: DefaultPluginPrefixResolverTest verifies lazy resolution only for matching plugins, and DefaultLifecycleExecutionPlanCalculatorTest covers both the negative case (GoalTask skips resolution) and the positive case (LifecycleTask triggers resolution).

This review was generated by an AI agent (Claude Code) and may contain inaccuracies. Please verify all suggestions before applying.

Claude Code on behalf of Guillaume Nodet

gnodet added a commit to gnodet/maven that referenced this pull request Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MNG-8693] Resolution of unneeded plugins

2 participants