UpgradeParentVersion: option to only upgrade external parents #4592
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's changed?
Added an
onlyExternal
optional parameter toUpgradeParentVersion
in order to only perform an upgrade when the parent is external to the repository.Had to adapt
ChangeParentPom
, which is used under the hood, because it wasn’t taking into account that an absent<relativePath>
really means../pom.xml
, notnull
or""
. I also changed the logic so that, ifnewRelativePath
is the empty string, it will replace an existing tag with<relativePath />
(i.e. same as if it were adding the tag).What's your motivation?
When the parent is in the same repository as the child, their versions are usually managed together, e.g. by the Maven Release Plugin or the Git Commit Id Maven Plugin.
This change allows to perform an upgrade of parents using wildcards for the
groupId
/artifactId
while making sure that it will not try to upgrade references to parents located in the same repository.For it to work properly, however, you need to properly specify
<relativePath />
(or<relativePath></relativePath>
) when the parent is located elsewhere. As people may forget about it (even though the IDE or Maven would warn about that), I didn’t make it the default. In fact, some tests would have been affected as well.Anything in particular you'd like reviewers to focus on?
My changes to
ChangeParentPom
didn’t break any test, which was a bit surprising, so I added 2 parameterized tests to cover different combinations ofrelativePath
.Have you considered any alternatives or workarounds?
Currently we are only upgrading parents with specific Maven coordinates, due to this limitation. We can’t have an “upgrade all parents” recipe that wouldn’t break multi-module projects (we are using the Git Commit Id Maven Plugin so the parent version in the pom.xml must not be touched for local poms)
Any additional context
The new
Parent.DEFAULT_RELATIVE_PATH
constant is only used byChangeParentPom
for now. I think it could make sense if it was used as a default, but I’m not sure the current Jackson configuration makes a difference between an absent tag and an empty tag, so this would need to be asserted first.Xml.Tag
appears to handle it properly.I also noticed that
ChangeTagValueVisitor
keeps the spaces in<relativePath />
when expanding it (so it becomes<relativePath >value</relativePath>
), which I find a bit strange, so I wrote the tests without space in the original pom.Checklist
multiModuleRelativePath()
andmultiModuleRelativePathChangeChildren()
tests, whose indentation was broken, and to the tests I added. IntelliJ also warns about trailing whitespace characters in most text blocks ofChangeParentPomTest
, which would get removed by formatting the file.