【问题标题】:Maven versions-maven-plugin versions plugin 2.2 -- Maven Uncle SituationMaven 版本-maven-plugin 版本插件2.2 -- Maven 大叔情况
【发布时间】:2023-09-28 18:16:01
【问题描述】:

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,它构建成功。

注意:在我的项目中,我有一个父部分,我依赖于 deploy-parent 工件,其组 ID“com.company.product”与我想要的组 ID 相同到 tools-parent 工件(我在上面粘贴的 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 versions:set -DnewVersion=0.0.7 命令运行成功并且 pom.xml 文件已成功更改为工具父工件的 &lt;version&gt;0.0.7&lt;/version&gt;

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

  1. 2.2 失败的任何原因?有什么办法可以解决?

【问题讨论】:

  • 这里最重要的是官方还没有给出公告...
  • 嗯..谢谢分享。

标签: maven nullpointerexception release maven-release-plugin versions-maven-plugin


【解决方案1】:

这似乎是一些错误。

解决方案:

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

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

【讨论】:

    【解决方案2】:

    【讨论】:

      【解决方案3】:

      我也遇到了 NPE,但事实证明原因与 suggested earlier 不同。我调试了versions-maven-plugin,发现NPE是由&lt;dependencyManagement&gt;中列出的依赖项缺少&lt;version&gt;声明引起的。这可以通过以下清单重现:

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

      【讨论】:

        【解决方案4】:

        只是添加到 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。

        【讨论】:

        • 像魅力一样工作,不需要在 pom.xml 中进行任何修改。感谢这个
        • 现在是 2018 年 7 月,2.2 版的插件还是坏掉了 :)