Maven版本-maven-plugin版本插件2.2 - Maven Uncle Situation

Aru*_*gal 18 release nullpointerexception maven maven-release-plugin versions-maven-plugin

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>
Run Code Online (Sandbox Code Playgroud)

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

注意:在我的项目中,我有一个父节,我依赖于deploy-parent工件,其组ID"com.company.product"是我想要的工具 - 父工件(其pom.xml)相同的组ID我已粘贴上面)但deploy-parent是另一个存储库/项目的工件.

当我运行:mvn版本: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
Run Code Online (Sandbox Code Playgroud)

现在,当我将versions-maven-plugin版本更改回2.1(我之前使用的是)时,上面的mvn版本:set -DnewVersion = 0.0.7命令正在成功运行并且pom.xml文件已成功更改为<version>0.0.7</version>对于工具 - 父工件.

对于2.2版,它给了我错误,而不是将版本更改为0.0.7.

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

Aru*_*gal 30

好像有些bug.

解决方案:

1.我要补充<groupId>com.company.product</groupId>外......部分财产以及即对于工具的父母,现在版本Maven的插件:2.2是工作的罚款,即我加了顶线(如下图所示).唯一的问题是,那么父部分的用途是什么(除了继承部署 - 父部署到工具 - 父项目的主要代码之外).为什么groupId需要定义artifactId工具的父节的输出 - 父元素已经存在于versions-maven-plugin:2.2的父节中,才能成功运行.

最重要的是:只有当你的项目/模块的pom.xml有一个<parent>部分,其中父部分的artifactId不是项目本身的父部分时(典型的 - Maven Uncle情况),即如果工具 - 父级,则会出现此问题artifact在另一个模块的父节中定义(比如tools-child),然后2.2版将成功运行.但是,如果tools-child的父节不包含artifactId作为"tools-parent",并且是ex:deploy-parent/some-different-project-artifact(它位于源代码控制工具中的不同项目中),那么为工具,孩子的artifactId,我们需要的groupId值也设置父部分之外,以及(即使的groupId父母节的的artifactId是相同/不同,以工具-孩子的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>
Run Code Online (Sandbox Code Playgroud)

-

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


小智 18

只是为了添加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
Run Code Online (Sandbox Code Playgroud)

您必须指定完整的group-id和artifact-id.