开发者

multiple project branches with maven

开发者 https://www.devze.com 2023-03-16 20:39 出处:网络
I am working with a pretty large project and want to work on multiple branches of it. One of it is at present an older version of the other, and the poms were the sam开发者_运维百科e. I\'d like to avo

I am working with a pretty large project and want to work on multiple branches of it. One of it is at present an older version of the other, and the poms were the sam开发者_运维百科e. I'd like to avoid changing the version numbers in the pom files since that may require rewriting all of them, and would later make merging more tricky. What is the simplest way to do this so that the jars produced by mvn clean install don't overwrite ones in a different branch placed in .mvn/repository ?

note: I am working with git and found the git-new-workdir script (available in the git source repo) to be very useful here in that it at least allows the jars produced in the source tree hierarchy to co-exist in different subdirectories.


So of course one simple answer is to have a repository for each branch. eg

  • .m2/repository
  • .m2/branch1/repository

Then one can run mvn install -o -Dmaven.repo.local=~/.m2/branch1/repository

Of course it would be nice if one could just clone with links the old repository so as not to have to download all files. This can be done with

$ cd .m2
$ mkdir branch1
$ find repository -type d -exec mkdir branch1/{} \;
$ find repository -type f -exec ln {} \;  branch1/{} \;

But the repository.xml seems to full of absolute directory url pointers. (why can't they use relative URLs?) Anyway, it does not seem to download all of them, or at least the compilation was a lot faster than expected.


The solution you discovered in your comment is the only non-intrusive one.

The next best thing is versions-maven-plugin, which automates changing the poms in the different branches. Sadly, I'm unaware of any component out there that allows you to automate the process of discouraging git from merging these changes along with others.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号