Maven 版本-maven-plugin 版本插件2.2 -- Maven 大叔情况

标签 maven nullpointerexception release 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>

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

注意 :在我的项目中,我有一个父部分,我依赖于部署父 Artifact ,其组 ID“com.company.product”与我想要的工具父 Artifact (我的 pom.xml已粘贴在上面)但 deploy-parent 是另一个存储库/项目的 Artifact 。

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

对于 2.2 版,它给了我错误,而不是将版本更改为 0.0.7。
  • 2.2失败的任何原因?可以做些什么来解决它?
  • 最佳答案

    这似乎是一些错误。

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

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

    关于Maven 版本-maven-plugin 版本插件2.2 -- Maven 大叔情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29995139/

    相关文章:

    java - 尝试在空对象引用上调用虚拟方法 'void com.jayfang.dropdownmenu.DropDownMenu.setmMenuCount(int)'

    svn - 如何发布Web应用程序?

    c# - 在调试与发布版本中获取有问题代码的行号

    java - Maven编译错误: (use -source 7 or higher to enable diamond operator)

    maven - 从父级构建 Maven 模块,无需父级引用

    java - 如何将InputStream转换为字符串?

    java - Java中的字符串和空指针

    java - Spring 错误 - springframework.web.client.HttpClientErrorException : 404 Not Found

    maven - maven Build Helper Maven Plugin的使用

    visual-c++ - dll大小(调试和发布)