有没有办法级联父pom的版本?

问题描述 投票:3回答:5

我有一个root pom.xml,它充当几个子pom.xml文件的父级,如果你有一个或两个子pom.xml文件,那就太棒了。我正在开发一个包含50多个子pom.xml文件的项目,并且会同时发布多个版本。在我需要更新父pom.xml文件的版本之前,一切都很棒,这可能很乏味。有没有办法将父pom.xml的版本级联到所有子pom.xml文件?

我有想法在父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

maven maven-3
5个回答
2
投票

你可以这样做:

有一个聚合器POM项目,您可以在其中指定所有子模块,然后在此聚合器项目上运行此目标:

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存储库中遵循“trunk,tags,branches”最佳实践,see this answer.


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


2
投票

我遇到了同样的问题,我所做的与迄今为止的任何建议略有不同。假设您的项目具有以下文件夹结构:

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

请注意,除了child5_of_child4之外,所有其他项目都作为父级顶层项目parent。这与文件夹结构无关。家长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

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


1
投票

在你的孩子pom.xml中:

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

-1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.