Maven versions-maven-plugin versions plugin 2.2 -- Maven大叔情况

Maven versions-maven-plugin versions plugin 2.2 -- Maven Uncle Situation

Maven 是 3.1.0。

我在我的项目 pom.xml 中使用 versions-maven-plugin:2.2(如下所示)。除了通常的 pom.xml 文件配置外,我只在下面显示主要代码快照:

<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>

    <artifactId>tools-parent</artifactId>
    <version>0.0.7-SNAPSHOT</version>
    <packaging>pom</packaging>

    <description>
        Infrastructure related to the &quot;vapp&quot; and
        &quot;deployer&quot; utilities.
    </description>

    <parent>
        <groupId>com.company.product</groupId>
        <artifactId>deploy-parent</artifactId>
        <version>0.0.6-SNAPSHOT</version>
    </parent>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-scm-plugin</artifactId>
                <version>1.9.4</version>
                <configuration>
                    <connectionType>connection</connectionType>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <!-- Make sure that only non-snapshot versions are used for the dependencies. Only active when property 'snapshotDependencyAllowed' is false. -->
                        <id>enforce-no-snapshots</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <skip>${snapshotDependencyAllowed}</skip>
                            <rules>
                                <requireReleaseDeps>
                                    <message>No Snapshots Allowed!</message>
                                </requireReleaseDeps>
                                <requireReleaseVersion>
                                    <message>No Snapshots Allowed!</message>
                                </requireReleaseVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

现在,当我 运行: mvn clean install 时,它构建成功。

注意:在我的项目中,我有一个父部分,我依赖于部署父工件,其组 ID "com.company.product" 是相同的组 ID我想要 tools-parent 工件(我在上面粘贴了 pom.xml)但是 deploy-parent 是另一个 repository/project.

的工件

当我 运行: mvn versions:set -DnewVersion=0.0.7 时,我收到以下错误消息。

[INFO] ------------------------------------------------------------------------
[INFO] Building tools-parent 0.0.7-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:set (default-cli) @ tools-parent ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /user/home/u100123/giga/tools
[INFO] Processing change of com.company.product:tools-parent:0.0.7-SNAPSHOT -> 0.0.7
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] tools-parent .................................... FAILURE [1.093s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.404s
[INFO] Finished at: Fri May 01 20:44:22 GMT-00:00 2015
[INFO] Final Memory: 12M/246M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.2:set (default-cli) on project tools-parent: Execution default-cli of goal org.codehaus.mojo:versions-maven-plugin:2.2:set failed. NullPointerException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

现在,当我将 versions-maven-plugin 版本更改回 2.1(我之前使用的版本)时,上面的 mvn versions:set -DnewVersion=0.0.7 命令成功运行,并且 pom.xml 文件成功更改为 <version>0.0.7</version> for tools-parent artifact。

对于 2.2 版,它给我错误并且没有将版本更改为 0.0.7。

  1. 2.2 失败的任何原因?可以做些什么来解决它?

这似乎是一些错误。

解决方案:

1。我必须在...部分 之外添加 <groupId>com.company.product</groupId> 属性 以及 即对于 tools-parent,NOW version-maven-plugin: 2.2 工作正常,即我添加了顶行(如下所示)。唯一的问题是,那么父部分的用途是什么(除了继承 deploy-parent 正在引入 tools-parent 项目的主要代码)。为什么 groupId 需要定义为 artifactId tools-parent 的父部分的输出,当它已经存在于 versions-maven-plugin:2.2 的父部分中才能成功工作。

最重要的是:只有当 pom.xml 的 project/module 有一个 <parent> 部分时才会出现此问题parent 部分的 artifactId 不是项目本身的父部分(典型的 - Maven Uncle 情况)即如果 tools-parent artifact 是在另一个模块的父部分中定义的(可以说 tools-child ) 然后版本 2.2 将成功运行。但是,如果 tools-child 的父部分不包含作为 "tools-parent" 的 artifactId,并且是 ex 的其他内容:deploy-parent/some-different-project-artifact(它位于源代码管理工具的另一个项目中) 然后,对于 tools-child artifactId,我们还需要在父部分之外设置 groupId 值(即使 groupId parent 部分的 artifactId 是 same/different tools-child 的 groupId)。

<groupId>com.company.product</groupId>
<artifactId>tools-parent</artifactId>
<version>0.0.7-SNAPSHOT</version>
<packaging>pom</packaging>

<description>
    Infrastructure related to the &quot;vapp&quot; and
    &quot;deployer&quot; utilities.
</description>

<parent>
    <groupId>com.company.product</groupId>
    <artifactId>deploy-parent</artifactId>
    <version>0.0.6-SNAPSHOT</version>
</parent>

--

2。切换回 versions-maven-plugin:2.1

发现此问题报告的错误:

https://github.com/mojohaus/versions-maven-plugin/issues/51

补充一下 Arun 回答的第 2 部分,插件 2.1 版的使用方法是:

mvn org.codehaus.mojo:versions-maven-plugin:2.1:set org.codehaus.mojo:versions-maven-plugin:2.1:commit -DnewVersion=0.0.7

您必须指定完整的组 ID 和工件 ID。

我也 运行 进入了 NPE,但事实证明原因与 不同。我调试了 versions-maven-plugin,发现 NPE 是由 <dependencyManagement> 中列出的缺少 <version> 依赖项声明引起的。这可以通过以下列表重现:

<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>com.example</groupId>
    <artifactId>npe</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>NPE Example</name>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <!-- missing <version>4.2.0.RELEASE</version> -->
                <scope>runtime</scope>
                <exclusions>
                    <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.0.RELEASE</version>
        </dependency>
    </dependencies>
</project>