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 "vapp" and
"deployer" 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时,它构建成功 .
NOTE :在我的项目中,我有一个父节,我依赖于deploy-parent artifact,其组ID为"com.company.product"与我想要的工具相同的组ID - 父工件(我上面粘贴了它的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文件已成功更改为 <version>0.0.7</version>
for tools-parent artifact .
在2.2版本中,它给出了错误,而不是将版本更改为0.0.7 .
- 2.2失败的原因是什么?可以做些什么来解决它?
4 回答
好像有些bug .
解:
1 . 我必须在... section as well 之外添加
<groupId>com.company.product</groupId>
属性,即对于tools-parent,NOW version-maven-plugin: 2.2 工作正常,即我添加了顶行(如下所示) . 唯一的问题是,版本-maven-plugin:2.2的父节中已经存在's the use of parent section then (apart from inheriting the main code of what deploy-parent is brining to tools-parent project). Why groupId needs to be defined output of parent section for artifactId tools-parent when it'已成功运行 .The most important thing is :仅当项目/模块的pom.xml具有
<parent>
部分且父部分的artifactId不是项目本身的父级(典型的 - Maven Uncle situation )时才会出现此问题,即如果工具 - 父工件在另一个模块的父节(让我们说工具 - 子)然后2.2版将成功运行 . 但是如果tools-child的父节不包含artifactId为"tools-parent"并且是ex的另外内容:deploy-parent / some-different-project-artifact( which resides in a different project in your source control tool )那么,对于tools-child artifactId,我们需要在外面设置 groupId 值父节的内容也是如此(即使父节的组IDId为's artifactId is same/different to tools-child' s groupId) .2 . 切换回versions-maven-plugin: 2.1
只是为了添加Arun答案的第2部分,使用插件2.1版的方法是:
您必须指定完整的group-id和artifact-id .
发现此问题报告的错误:
https://github.com/mojohaus/versions-maven-plugin/issues/51
我也遇到了一个NPE但事实证明原因与suggested earlier不同 . 我调试了versions-maven-plugin并发现NPE是由
<dependencyManagement>
中列出的依赖项缺失<version>
引起的 . 可以使用以下列表重现: