Skip to content

MNG-7884: Add --print-build-order option to print reactor build order without building#12486

Open
AbdelHamdyGhanem wants to merge 3 commits into
apache:masterfrom
AbdelHamdyGhanem:MNG-7884-reactor-build-order-option
Open

MNG-7884: Add --print-build-order option to print reactor build order without building#12486
AbdelHamdyGhanem wants to merge 3 commits into
apache:masterfrom
AbdelHamdyGhanem:MNG-7884-reactor-build-order-option

Conversation

@AbdelHamdyGhanem

Copy link
Copy Markdown

What

Adds a new CLI flag --print-build-order (short form -pbo) that prints the reactor's
topologically-sorted build order and exits, without executing the build lifecycle.

Why

Closes #8733 (MNG-7884). This is useful for analyzing a multi-module build's execution
order without committing to a full build — e.g. in CI diagnostics, scripting, or simply
understanding module interdependencies in large reactors.

How

  • Added printBuildOrder() to the MavenOptions API interface (api/maven-api-cli).
  • Implemented option parsing in CommonsCliMavenOptions (new PRINT_BUILD_ORDER constant
    and Option registration in the nested CLIManager).
  • Added the corresponding merge-layer override in LayeredMavenOptions.
  • (In progress) Wiring the parsed value into MavenExecutionRequest via
    MavenInvoker.populateRequest(...).
  • (In progress) Adding isPrintBuildOrder()/setPrintBuildOrder(boolean) to
    MavenExecutionRequest/DefaultMavenExecutionRequest.
  • (In progress) In DefaultMaven.doExecute(...), after the authoritative buildGraph(session)
    call succeeds, checking the flag and — if set — printing the sorted project list and
    returning a clean success result before lifecycleStarter.execute(session) runs.

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.

@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.

Review: MNG-7884 — Add --print-build-order option

Verdict: Incomplete — needs more work before merge

The PR adds CLI option parsing for --print-build-order / -pbo across the three expected files in the options layer (MavenOptions.java, CommonsCliMavenOptions.java, LayeredMavenOptions.java). The option name is clear, the short code -pbo doesn't conflict with existing options, and it follows Maven CLI conventions.

However, the feature is not yet functional — the PR description itself notes several pieces are "(In progress)":

Findings

1. Feature not wired up (high)
The option is parsed but never consumed. There is no code in MavenInvoker, MavenExecutionRequest, or DefaultMaven.doExecute() that reads printBuildOrder() and acts on it. Running mvn --print-build-order would accept the flag but silently do nothing.

→ The PR should either be marked as draft until wiring is complete, or include the remaining implementation.

2. Missing @Nonnull annotation (medium)
Every other Optional<...> method in MavenOptions.java has @Nonnull on the return type. The new printBuildOrder() omits it.

3. No tests (medium)
No unit or integration tests are included. At minimum, a parsing test for CommonsCliMavenOptions confirming -pbo / --print-build-order is correctly parsed would be expected.

4. Javadoc @return style (low)
The @return tag deviates from the established pattern. Other methods use:

an {@link Optional} containing true if ..., false if ..., or empty if not specified

The new method uses a different format.

Positive notes

  • The JIRA issue MNG-7884 is valid and the feature is genuinely wanted
  • Option naming is good and conflict-free
  • Placement in the options interface is reasonable

This review was generated by an AI agent 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 Jul 13, 2026
@cstamas

This comment was marked as off-topic.

@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.

Re-review after new commits

Thanks for addressing the feedback! Two items fixed:

  • @nonnull annotation — added, now consistent with all other Optional<...> methods
  • Javadoc @return style — now matches the established pattern

Still outstanding:

  1. Feature not wired up (high) — the option is parsed but still never consumed anywhere in the execution path. mvn --print-build-order would accept the flag but silently do nothing.
  2. No tests (medium) — at minimum a parsing test for CommonsCliMavenOptions would be expected.

Consider marking as draft until the wiring (into MavenExecutionRequest / DefaultMaven.doExecute()) is complete, or adding the remaining implementation in follow-up commits.

This review was generated by an AI agent 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 Jul 13, 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-7884] Add a command line option to just print the reactor build order

3 participants