19

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”与我想要的工具父工件(其 pom.xml我已经粘贴在上面)但是 deploy-parent 是另一个存储库/项目的工件。

当我运行: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版本:set -DnewVersion = 0.0.7命令成功运行并且pom.xml文件成功更改为<version>0.0.7</version>对于工具父工件。

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

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

4 回答 4

31

这似乎是一些错误。

解决方案:

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

最重要的是:仅当您的项目/模块的 pom.xml 有一个<parent>部分,其中父部分的 artifactId 不是项目本身的父级时才会出现此问题(典型的 - Maven Uncle 情况),即如果 tools-parent工件是在另一个模块的父部分(比如说工具子)中定义的,那么 2.2 版将成功运行。但是,如果 tools-child 的 parent 部分不包含 artifactId 作为“tools-parent”并且是其他的东西:deploy-parent/some-different-project-artifact(它位于源代码控制工具中的不同项目中)然后,对于工具子 artifactId,我们还需要在父部分之外设置groupId值(即使groupId父部分的artifactId与 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 . 切换回版本-maven-plugin:2.1

于 2015-05-01T21:17:51.117 回答
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

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

于 2015-07-10T01:18:22.210 回答
3

发现这个问题报告了这个错误:

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

于 2015-05-01T21:35:15.937 回答
2

我也遇到了 NPE,但事实证明原因与之前建议的不同。<version>我调试了versions -maven-plugin,发现NPE是由<dependencyManagement>. 这可以通过以下清单重现:

<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>
于 2015-08-31T08:54:59.930 回答