【问题标题】:maven-release-plugin does not work for multi-module POMsmaven-release-plugin 不适用于多模块 POM
【发布时间】:2013-05-28 11:45:09
【问题描述】:

插件版本: 2.0

我正在尝试使用 maven-release-plugin 来设置父 POM 和所有模块的版本。

使用以下父 POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>uk.co.mycompany</groupId>
    <artifactId>myProject</artifactId>
    <version>latest-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>My Project</name>

    <modules>
        <module>../../subPom1</module>
        <module>../../subPom2</module>
            <module>../../subPom3</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.0</version>
                <executions>
                    <execution>
                        <phase>clean</phase>
                        <id>set-release-versions</id>
                        <configuration>
                            <developmentVersion>1.1.8</developmentVersion>
                            <autoVersionSubmodules>true</autoVersionSubmodules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

在运行mvn clean install -DskipTests -Pdeploy 时,完全忽略在清理阶段运行插件的配置,并使用值“latest-SNAPSHOT”进行构建。

我期待它从插件配置中获取值“1.1.8”。

每个子 POM 等价于:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>uk.co.mycompany</groupId>
        <artifactId>myProject</artifactId>
        <version>latest-SNAPSHOT</version>
        <relativePath>../../System/build/parentPom.xml</relativePath>
    </parent>

    ...

</project>

为什么忽略配置?

编辑 #1: 文件系统结构按要求:

/
 |- system
 |  |
 |  |- build
 |      |
 |      |-parentPOM file
 |
 |- business
 |     |
 |     | - childPOM1
 |     | - childPOM2
 |- client
 |     | - childPOM3
 |     | - childPOM4

忽略 SSCCE 中的 .../... - 我已经混淆了真实值以概括地描述问题。

编辑#2:我已按照建议将定义移至&lt;pluginManagement&gt;,但问题仍然存在(未使用插件,没有向控制台反馈):

<pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.0</version>
                    <configuration>
                        <developmentVersion>1.1.8</developmentVersion>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

【问题讨论】:

  • 首先您应该将maven-release-plugin 的版本更新为2.4.1 而不是2.0(这真的很旧)。是否可以显示项目的文件夹结构?啊。为什么将 maven-release-plugin 绑定到 clean 阶段?这没有意义?
  • 嗨。我认为我应该让它在一开始就运行,所以我将它绑定到“干净”。恐怕我被限制使用 2.0。在我的 Eclipse 环境中,每个项目都是一个单独的文件夹。我应该补充一点,这个构建将 JAR 和 WAR 构造成一个 EAR 罚款 - 只是这个插件没有绑定到任何目标,因此被完全忽略。
  • 为此,您应该使用 pluginManagement 来配置您所描述的内容。但是你真的需要更新版本,因为旧版本有错误。每个项目都有一个单独的 Eclipse 项目是可以的。但此外,我看到您使用parentPoml.xml 作为父级和不同级别,看起来不太好。有这样不同层次的关系有充分的理由吗?
  • 按要求添加结构。除了遗留原因之外,没有充分的理由对其进行布局。这不是我的选择,但是正在解决每个孩子的路径以完成没有错误的构建 - 只是 maven-release-plugin 没有订阅目标并且没有触发。
  • 我已按照建议将配置移至 pluginManagement,但问题仍然存在。该插件的文档很糟糕 - 没有给出使用 POM 配置的示例。

标签: maven maven-release-plugin


【解决方案1】:

您忘记设置插件的目标。您配置了 update-versions 目标所需的参数,但您告诉 maven 只在 clean 阶段执行插件,而不是插件的哪个目标。所以它什么都不做。

当你尝试 mvn clean 时检查 maven 日志,它应该只显示:

[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ test ---

当您将配置更改为:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.0</version>
            <executions>
                <execution>
                    <phase>clean</phase>
                    <id>set-release-versions</id>
                    <goals><goal>update-versions</goal></goals>
                    <configuration>
                        <developmentVersion>1.1.8</developmentVersion>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

在 maven 的 clean 阶段调用目标 update-versions。

[INFO] --- maven-release-plugin:2.0:update-versions (set-release-versions) @ bdd ---

不确定这是否会解决您的所有问题,但这会强制 maven 像预期的那样在 clean 阶段执行插件。

然而,发布插件在仅用于更改版本时需要很多特殊设置(如 scm 连接)。所以我建议使用versions-maven-plugin

 <build>
    <plugins>
        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>set</goal>
                    </goals>
                    <phase>clean</phase>
                    <configuration>
                        <newVersion>1.1.8</newVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

【讨论】:

  • 感谢您的回答。希望这将在网络上占据一席之地,并作为插件的模板供其他人效仿!您使用versions-maven-plugin 进行版本控制的建议肯定与其他论坛中给出的建议一致,我将考虑使用此插件。
【解决方案2】:

最后还是放弃了。

Stack Overflow 等都充满了像这个问题一样没有答案的问题,并且插件文档未能提供 POM 格式的使用示例,告诉我我需要知道的关于这个插件的一切。

我的解决方法是将父 POM 的版本设置为“latest-SNAPSHOT”并引入一个名为 &lt;myproject.release.version&gt;, 的属性,我在任何我想打印版本号的地方都使用它。

特别是,我想在 WAR 文件的清单中打印版本号。我这样做如下:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
            <configuration>
                    <archive>
                          <manifest>
                               <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                           <manifestEntries>
                                    <Implementation-Version>${myproject.release.version}</Implementation-Version>
                                </manifestEntries>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>war</id>
                        <phase>package</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                        <configuration>
                            <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
                            <filters>
                                <filter>${project.parent.basedir}/filter/${webapp.filter}.properties</filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
 </plugin>

使用上述配置,我将发布号作为 Maven 属性放入我的清单中。

在我的应用程序中,我从那里拿起它并在屏幕上绘制它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 2016-02-16
    • 2013-04-24
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    相关资源
    最近更新 更多