且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在多模块项目中处理Maven版本?

更新时间:2022-12-13 10:29:21

我是否必须自己照顾所有模块版本,还是有一个插件可以为我完成所需的工作?

Do I have to take care for all the module versions by myself or is there a plugin that is able to do the required work for me?

好吧,如果您不想使各种工件(项目,库)的​​版本与all/pom.xml中定义的版本保持同步(即仅继承整个层次结构),恐怕您将不得不开始手动管理它们.我只是不确定要理解为什么即使您不对其进行任何更改,您也不会颠覆lib2的版本.在您当前的svn存储库结构中,所有工件都以某种方式具有相同的发布生命周期(当您标记中继时,您将标记其中的所有内容).

Well, if you don't want to keep the versions of the various artifacts (projects, libs) in sync with the version defined in all/pom.xml (i.e. just inherit it through the whole hierarchy), I'm afraid you'll have to start to manage them manually. I'm just not sure to understand why you wouldn't bump the version of say lib2 even if you didn't make any change to it. With your current svn repository structure, all artifacts have the same release lifecycle somehow (when you'll tag the trunk, you'll tag everything in it).

现在,如果p1p2(为简单起见,我将忽略这些库)具有独立的发布周期,那么我建议您使用多个主干/标签/分支" "此线程:

Now, if p1 and p2 (I'll ignore the libs for the sake of simplicity) have an independent release cycle, I would recommend a multiple "trunk/tags/branches" structure as described in this thread:

myrepo
  + .links (2)
    + trunks
      + pom.xml
  + parent-pom (1)
    + trunk
      + pom.xml
  + project-A
    + trunk
      + pom.xml
  + project-B
    + trunk
      + pom.xml 

1)项目的父POM具有 自己的发布周期.每一个 组件的POM将其用作父对象 (仅用groupIdartifactId,否relativePath).为了 发布,您必须发布 父POM首先.

1) The parent POM of the project has an own release cycle. Every component's POM will use it as parent (referenced simply with groupId and artifactId, no relativePath). For a release you'll have to release the parent POM first.

2)这是启用的构造 轻松检出特定分支 项目的范围,即通常 树干.一个Subversion用户检出 myrepo/.links/trunk抢先一步 修改所有资料.诀窍是 该目录包含 外部链接(即与 svn:externals 属性) 此其他所有模块的主干 项目(父pom,项目A, 项目B).在这里的pom.xml 目录从不释放,它 仅包含用于的模块部分 这三个模块可以实现多种 模块构建.有了这个构造 您可以轻松设置分支 例如:

2) This is a construction to enable easy check outs of a specific branch of the project i.e. normally the trunk. A subversion user checks out myrepo/.links/trunk to get the head revision of all sources. The trick is, that that directory contains external links (i.e. with the svn:externals property) to the trunks of all other modules of this project (parent-pom, project-A, project-B). The pom.xml in this directory is never released, it contains simply a modules section for the three modules to enable a multi module build. With this construct you're able to setup easily branches e.g.:

myrepo
  + .links
    + branch-2.x
      + pom.xml

我已经多次使用了这个设置(我已经在SO上写过它了,请参阅下面的相关问题),它工作得很好.实际上,包括Maven在内的许多项目都在使用这种方法,这不是一种幻想.

I've used this setup many times (I already wrote about it here on SO, see the related questions below), it works very well. Actually, many projects, including Maven, are using this approach, it's not a fantasy one.

这不会解决您的自动"版本处理问题(我不知道有什么解决方案),但至少,此结构与

This will not solve your "automagic" version handling (I don't know any solution for that) but at least, this structure plays nicely with the Maven Release Plugin and would support your independent release cycle requirements.

  • Building Maven
  • XWiki Platform Structure
  • Cargo SVN
  • Maven parent pom vs modules pom
  • Migrating to maven from an unusual svn directory structure?