Skip to content

Allow override pushChanges from terminal#1394

Open
ssheikin wants to merge 2 commits into
apache:masterfrom
ssheikin:ssheikin/prepare-push-changes
Open

Allow override pushChanges from terminal#1394
ssheikin wants to merge 2 commits into
apache:masterfrom
ssheikin:ssheikin/prepare-push-changes

Conversation

@ssheikin

@ssheikin ssheikin commented Oct 7, 2025

Copy link
Copy Markdown

mvn release:prepare -DpushChanges

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 integration tests successfully (mvn -Prun-its verify).

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.

builder.setPushChanges(pushChanges);
return this;
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

should other properties/methods from ReleaseDescriptorBuilder be overriden here too?

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.

Isn't

enough in the context of the prepare goal?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's not enough.

PTAL on repro: https://github.com/ssheikin/maven-release-1394-repro#running-it

Also, let me share AI reasoning about it:

  Here's the actual Maven mechanism, in three steps.

  1. The annotation becomes a default expression in plugin.xml.
  @Parameter(defaultValue = "true", property = "pushChanges") (AbstractScmReadWriteReleaseMojo.java:79) is compiled by maven-plugin-tools into the plugin descriptor as a default configuration entry, roughly:

  <configuration>
    <pushChanges default-value="true">${pushChanges}</pushChanges>
  </configuration>

  So out of the box, the parameter's configured value is the expression ${pushChanges}. property is just "the name of the expression that goes in this slot."

  2. The POM <configuration> is merged on top of that descriptor default (a DOM merge).
  When your POM declares:

  <configuration><pushChanges>false</pushChanges></configuration>

  Maven merges it over the descriptor config with Xpp3Dom merge rules. Same element name → the POM's child replaces the descriptor's. The effective config for the mojo execution is now the literal:

  <pushChanges>false</pushChanges>   <!-- the ${pushChanges} expression is gone -->

  3. Configuration injection evaluates expressions — but there's no longer one.
  The component configurator walks the merged config and, for each ${...}, calls PluginParameterExpressionEvaluator, which is what resolves ${pushChanges} against session.getUserProperties() (your -D values).
  But after step 2 the value is the plain string "false" — no ${...}, nothing to evaluate, -D is never read. The field is set to false.

  So the rule is: -Dxxx only feeds a parameter whose configured value is still the ${xxx} expression — i.e. one you did not set explicitly in <configuration>. property supplies a default, it is not an override
  channel.

  Why it feels surprising: -DskipTests "always works" only because projects rarely hardcode <skipTests> in surefire's <configuration> — the ${skipTests} expression stays live. Hardcode
  <skipTests>false</skipTests> and -DskipTests=true is ignored the exact same way.

  Why that forces the fix where it is: once the literal wins, the mojo field is false, so descriptor.setPushChanges(pushChanges) can only ever propagate false. The raw -DpushChanges survives only as
  session.getUserProperties(), which reaches DefaultReleaseManager.prepare(...) as prepareRequest.getUserProperties() — hence the override must be applied there, not at the mojo.

@ssheikin ssheikin force-pushed the ssheikin/prepare-push-changes branch from da46e8f to 2661d63 Compare June 16, 2026 11:59
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.

2 participants