Git merge conflict only on version tag in pom.xml
Solution 1
What I always do is change the version of the modules using the maven versions plugin, before merging from another branch (with a different version):
mvn versions:set -DnewVersion=1.1 -DgenerateBackupPoms=false
That'll change the version of all the current modules (parent and children) to the one you specify as the newVersion parameter. After changing the version, make a new commit (git commit...) and then do the merge. I've got all of this automated using a Jenkins task, but it shouldn't be difficult to implement it in other ways (e.g. sh script).
Solution 2
You probably have a few options. None of which are perfect :-/
1) you can use 'git merge -s ours', but you should only do that when you know you don't need the rest of the changes too.
2) You can also use git rerere, which helps resolve conflicts by memorizing what you did last time. You can enable its usage globally so it always "just works" by setting rerere.enabled. Or you can read the man page and do it by hand as well.
Solution 3
You could also use a custom merge driver, as in pom-merge-driver. Depending on your workflow you might want to merge pom as a normal file, except treating the project version differently: always take the merging branch version, or make an exception when merging to the develop branch...
Solution 4
I had the same problem and all solutions that i found didn't do it, imo, correct. Finally i wrote a merge driver which only takes care of the project/parent version and only them. No dependency version is changed nor the format of the xml file.
I released it a few minutes ago @ https://github.com/cecom/pomutils. If you have any questions, let me know.
Solution 5
Take a look at resolve-maven-version-conflicts.pl
. It's a mergetool specifically to resolve pom conflicts. It'll ignore any change where both sides are -SNAPSHOT
versions, but leave any other conflicts for further resolution.
![Abidi](https://i.stack.imgur.com/j9WBF.png?s=256&g=1)
Abidi
Updated on June 22, 2022Comments
-
Abidi about 2 years
Is there a way to avoid merge conflicts in version tag in
pom.xml
when merging master into a branch? I have quite a few pom files, 80, and all of them have same version which is different from one in master. It's laborious and time-consuming to executegit mergetool
for 80 pom files just for a version tag. -
Wes Hardaker almost 12 yearsrerere rocks. In fact, it rocks so much you frequently forget you're using it.
-
Sven Oppermann over 9 yearsThe tool got now some more improvements. Now you can also auto resolve property values and it is possible to write your own conflict resolution rule. Have a look :-)
-
DarVar over 7 yearsOption 2) won't work if the version changes in anyway since git rerere recorded the merge conflict resolution. So not really an option IMO.