Fix mvnup comment formatting for override comments#12443
Conversation
When mvnup inserts "Override version inherited from parent" comments before plugin elements, the comment was placed on the same line as the preceding </plugin> closing tag, causing POM formatting violations in projects that enforce XML formatting (e.g. via spotless). The fix sets precedingWhitespace on the Comment node to match the plugin element's indentation, ensuring the comment appears on its own line. Fixes gnodet/maven4-testing#23134 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Note: This PR is a workaround for a missing API in DomTrip. The Filed upstream: maveniverse/domtrip#254 Once DomTrip adds |
Replace the manual precedingWhitespace() workaround with the new Editor.insertCommentBefore() method added in DomTrip 1.6.0 (maveniverse/domtrip#254), which handles whitespace automatically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Updated: upgraded DomTrip to 1.6.0 which includes the new |
Summary
PluginUpgradeStrategyto setprecedingWhitespaceonCommentnodes inserted before plugin elements, so the "Override version inherited from parent" comment appears on its own line instead of being appended to the preceding</plugin>closing tagProblem
When mvnup adds plugin management entries for plugins inherited from a remote parent, it inserts a
<!-- Override version inherited from parent -->comment before the<plugin>element. TheComment.of(...)factory creates a comment with noprecedingWhitespace, causing it to render on the same line as the previous</plugin>closing tag:This breaks projects that enforce POM formatting (e.g. via
spotless-maven-plugin), which expect:Fix
Set
precedingWhitespaceon theCommentnode to match the plugin element's indentation at both insertion sites inPluginUpgradeStrategy:addPluginManagementEntryFromUpgrade()— forbuild/pluginManagement/pluginsaddDirectPluginOverrides()— forbuild/pluginsFixes gnodet/maven4-testing#23134
Test plan
PluginUpgradeStrategyTestpasses (31 tests)assertFalse(xml.contains("</plugin><!--"), ...))maven-climodule verify passes (468 tests)🤖 Generated with Claude Code