2013-04-22 112 views
3

我有一个根pom.xml作为几个子pom.xml文件的父节点,如果您有一个或两个子pom.xml文件,这非常棒。我正在研究一个拥有50多个子pom.xml文件的项目,并且一次发布多个发布。一切都很好,直到我需要更新父pom.xml文件的版本,这可能很乏味。有没有办法将父pom.xml的版本级联到所有子pom.xml文件?有没有一种方法可以级联父pom的版本?

我的想法是在当前版本的父pom.xml中创建一个属性,但这不起作用。

编辑

这里是我的孩子的pom.xml文件的范例:

<parent> 
    <groupId>myGroup</groupId> 
    <artifactId>myArtifactId</artifactId> 
    <version>1.0</version> <!-- This is the value that I would like to parameterize in my child pom.xmls --> 
    <relativePath>../../pom.xml</relativePath> 
</parent> 

顺便说一句,我使用Maven 3.0.3

+0

看起来像这已被问过... http://stackoverflow.com/questions/1981151/warning-on-using-project-parent-version-as-the-version-of-a-module-in -maven-3 – DaveRlz 2013-04-22 14:40:11

+0

@DaveRlz几乎,但不完全是 – bakoyaro 2013-04-22 14:48:21

+1

有一点在回应中说'要在子模块中使用父pom版本,只需从子poms中删除标记,它们将继承父母。这不是你想要做的吗? – DaveRlz 2013-04-22 14:51:21

回答

2

你可以这样来做:

有一个聚合聚甲醛项目,在您指定的所有子模块,然后运行在此聚合项目这个目标:

mvn versions:update-parent 

这将更新具有新父版本的所有子模块。

或者,您可以在每次发布之前使用相同的内容:准备子模块的目标,从而避免创建聚合器模块。

所以,如果你想发布一个孩子模块,你只要运行这个目标:

mvn versions:update-parent release:prepare 

这将确保正在为释放准备之前,父进程得到一个新的版本更新。

我在你的评论中读到你缺少一个scm标签。破坏情况下的使用示例可能是:

<scm> 
    <developerConnection>scm:svn:https://your.domain/scm/svn/yourModule/trunk/</developerConnection> 
</scm> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-release-plugin</artifactId> 
      <configuration> 
       <tagBase>https://your.domain/scm/svn/yourModule/tags</tagBase> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

如果没有正确配置的scm,发布插件无法正常工作。

你并不需要配置的情况下,在发布插件的tagbase标签您按照“主干,标签,分支”最好在你的svn库的做法,see this answer.

1

在你的孩子pom.xml:

<parent> 
    <groupId>groupId</groupId> 
    <artifactId>parent.artifactId</artifactId> 
    <version>version</version> 
    <relativePath>../parent-pom</relativePath> 
</parent> 
<artifactId>child.artifactId</artifactId> 
+1

你不需要在这种情况下指定relativePath,因为父母是默认的。 – khmarbaise 2013-04-22 14:45:21

+0

这取决于你的目录组织。在某些情况下,你可以让孩子不在父目录中,所以你需要指定相对路径;) – yodamad 2013-04-22 14:54:00

+0

我知道它可以完成,但这不是好的做法;-) – khmarbaise 2013-04-22 15:02:38

2

我假设你有这样的事情:

+--root (pom.xml) 
    +--- module1 (pom.xml) 
    +--- 

在根pom.xml中:

<project ..> 

    <groupId>the.company.project</groupId> 
    <artifactId>the-artifact</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    ... 
</project> 

而在孩子的,你应该有:

<project ..> 

    <parent>   
    <groupId>the.company.project</groupId> 
    <artifactId>the-artifact</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>the-artifact-child</artifactId> 

</project> 

对于这样的目的,你应该使用maven-release-plugin,它处理root中的版本更新以及childs。如果你不使用maven-release-plugin,你可以使用versions-maven-plugin来处理相同的事情。

+0

我正在尝试maven-release-plugin,但由于缺少scm属性而出现一些错误。你知道最小的配置是什么吗? – bakoyaro 2013-04-22 18:07:37

-1

只是不要把版本放在孩子poms。它是自动继承的。如果你在那里编辑,它会在Eclipse插件中显示为警告。

+0

对不起,当我尝试你的答案时出现此错误: \t [错误]项目myGroup:验收测试:[unknown-version](C:\ git \ my_app \ 1.0 \ my_app \ acceptance-tests \ pom .xml)有1个错误 [错误]'parent.version'丢失。 @第8行第13列 – bakoyaro 2013-04-22 15:48:08

+2

@bakoyaro号码在中,您需要指定父版本。你不指定孩子的版本。 – djechlin 2013-04-22 16:15:44

1

我有同样的问题,我所做的就是稍微与迄今为止所提出的任何不同。假设你的项目有以下结构:

parent 
+-- child1 
    +-- child2_of_parent 
    +-- child3_of_parent 
+-- child4 
    +-- child5_of_child4 

家长pom.xml

<groupId>...</groupId> 
<artifactId>...</artifactId> 
<version>1.1-SNAPSHOT</version> 

所有的孩子pom.xml除了child5_of_child4有父child4

<parent> 
    <groupId>...</groupId> 
    <artifactId>parent</artifactId> 
    <version>1.1-SNAPSHOT</version> 
    <relativePath>../parent</relativePath> 
</parent> 

你去父目录并将其版本从版本1.1-SNAPSHOT更改为1.2-SNAPSHOT。然后,你做(更多详情here):

mvn versions:update-child-modules 

由于这不是递归的,它只能在你的父项目的直接孩子。换句话说,除child5_of_child4之外,所有子模块都将更新为指向父1.2-SNAPSHOT

相关问题