Skip to content

Maven: only rewrite a declaration's own <version> when bumping - #16969

Merged
v-thavaahariharangit merged 13 commits into
mainfrom
copilot/maven-bump-enforcer-plugin
Nov 18, 2026
Merged

v-thavaahariharangit merged 13 commits into
mainfrom
copilot/maven-bump-enforcer-plugin

Conversation

@v-thavaahariharangit

@v-thavaahariharangit v-thavaahariharangit commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What are you trying to accomplish?

Fixes: #16797

Maven::FileUpdater#updated_file_declaration replaced every occurrence of the old version string in the whole <plugin>/<dependency> node. A plugin bump therefore also rewrote matching values nested in <executions> or <configuration>.

For example, bumping maven-enforcer-plugin 3.6.3 → 3.7.0 also changed <requireMavenVersion><version>3.6.3</version>, which raised the project's minimum Maven version to one that doesn't exist.

Now only the declaration's own <version> child is rewritten.

Anything you want to highlight for special attention from reviewers?

  • Depth check: each <version> match is checked for element depth 1 within the declaration, using the new element_depth helper, which counts tags (ignoring comments and self-closing tags) in the text before the match.
    • The issue's suggested fix cuts the declaration off at the first <executions>/<configuration>/<dependencies>. That misses plugins that declare <version> after those blocks, so I used a depth check instead.
  • Comment handling: the version regex still allows XML comments between the value and </version>. The existing "with a comment on the version" spec depends on this.
  • Rubocop: I added rubocop:disable Metrics/ClassLength on FileUpdater, which now exceeds the 350-line limit.
  • Sibling ecosystems: I did not check gradle or sbt for the same problem.

How will you know you've accomplished your goal?

  • Added the plugin_config_same_version.xml fixture, which is the minimal repro from the issue, and a spec that asserts the plugin <version> becomes 3.7.0 while requireMavenVersion stays 3.6.3.
  • The existing Maven specs still pass, including the version-comment and whitespace cases.

In the local run I have confirmed the expected behaviour
image

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

Copilot AI balanced review requested due to automatic review settings November 18, 2026 11:56

Copilot AI 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.

Copilot wasn't able to review any files in this pull request. Check if the Files changed in this pull request are included in default exclusions.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 12:03
@v-thavaahariharangit v-thavaahariharangit changed the title [WIP] Update maven-enforcer-plugin from 3.6.3 to 3.7.0 Maven: only rewrite a declaration's own <version> when bumping Nov 18, 2026
@v-thavaahariharangit
v-thavaahariharangit marked this pull request as ready for review November 18, 2026 12:03
@v-thavaahariharangit
v-thavaahariharangit requested a review from a team as a code owner November 18, 2026 12:03
@github-actions github-actions Bot added the L: java:maven Maven packages via Maven label Nov 18, 2026

Copilot AI 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.

🟡 Changes recommended

The updater can fail on valid plugin declarations containing CDATA, comments, or tag whitespace, while missing packaging metadata causes the regression test to bypass the plugin rewrite.

3 open issues

Review effort: Balanced

… spec metadata

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI 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.

🔵 Needs a closer look

The updater fails on valid version elements with attributes and can miscalculate XML depth, skipping replacements and raising Expected content to change!.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Version tag pattern rejects tags with attributes

maven/​lib/​dependabot/​maven/​file_updater.rb:335

The new opening-tag pattern rejects valid version elements with attributes, such as <version xmlns="http://maven.apache.org/POM/4.0.0">3.6.3</version>. Both FileParser and DeclarationFinder remove namespaces and recognize this requirement, and the previous replacement updated it. Now no replacement occurs, so update_version_in_file raises Expected content to change!. Allow attributes on the opening version tag while preserving them in the replacement.

Medium severity Quoted attributes and processing instructions corrupt tag depth

maven/​lib/​dependabot/​maven/​file_updater.rb:354

When configuration precedes the plugin's own version, a self-closing tag such as <arg value="a > b"/> is counted as an opening element, so the version update is skipped and update_version_in_file raises Expected content to change!. Processing instructions containing tag-shaped text can also corrupt the depth calculation. Consume quoted attributes and processing instructions as complete tokens, exclude processing instructions from the depth count, and add regression coverage for these cases.

3 resolved since last review

Review effort: Balanced

…t to quoted attrs and self-closing tags

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 12:22

Copilot AI 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.

🔵 Needs a closer look

Human review is needed because XML parsing edge cases can cause valid version updates to fail or alter commented-out versions.

No open issues 🎉

Review effort: Balanced

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because the CDATA matching change can leave whitespace-padded versions unchanged and cause updates to fail.

No open issues 🎉

Review effort: Balanced

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:05

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because the opening-tag regex mishandles > inside quoted XML attributes, causing previously working Maven version updates to fail.

No open issues 🎉

Review effort: Balanced

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:14

Copilot AI 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.

🔵 Needs a closer look

Human assessment is needed because the regex can skip valid Maven version declarations with adjacent processing instructions, leaving versions unchanged and causing updates to fail.

No open issues 🎉

Review effort: Balanced

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:24

Copilot AI 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.

🟢 Approval recommended

No active review issues block approval of the targeted Maven version-update change.

No open issues 🎉

Review effort: Balanced

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 13:49

Copilot AI 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.

🟢 Approval recommended

No active review issues are reported for the change limiting Maven version updates to declaration-level version elements.

No open issues 🎉

Review effort: Balanced

@v-thavaahariharangit
v-thavaahariharangit merged commit 2d05f9d into main Nov 18, 2026
106 of 109 checks passed
@v-thavaahariharangit
v-thavaahariharangit deleted the copilot/maven-bump-enforcer-plugin branch November 18, 2026 15:20
@pzygielo

pzygielo commented Nov 18, 2026 •

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L: java:maven Maven packages via Maven

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maven: bumping a plugin also rewrites a <version> with the same value inside that plugin's <configuration>

6 participants