我有一个项目文件夹结构,我们在其中使用父 pom,每个子文件夹都包含自己的 pom.xml。像这样:
Project (pom.xml)
|- Addon-1 (pom.xml)
|- Addon-2 (pom.xml)
|- Addon-2 (pom_hotfix.xml)
Addon-1 和 Addon-2 pom.xml 包含一个父级:
<parent>
<groupId>com.abc</groupId>
<artifactId>abc</artifactId>
<version>1.0.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
此外,Addon-2 文件夹包含第二个 pom 文件,它没有父级. 这是强制性的,因为不允许修补程序包含整个父级。
我的 pom_hotfix.xml 看起来像:
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>hotfix</artifactId>
<groupId>com.abc</groupId>
<name>hotfix</name>
<version>1.0.10</version>
<packaging>jar</packaging>
<build>
<resources>
<resource>
<directory>src/main/overlay/</directory>
<excludes>
<exclude></exclude>
</excludes>
</resource>
</resources>
</build>
</project>
现在问题出在 org.codehaus.mojo:versions-maven-plugin set 命令上。如果我调用如下:
mvn -B org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion=2.0.2 -f pom_hotfix.xml -X
我总是收到以下错误。
✔ mvn -B org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion=2.0.2 -f pom_hotfix.xml
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.abc:hotfix >---------------
[INFO] Building hotfix 1.0.10
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.7:set (default-cli) @ hotfix ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /Users/abc/Project/
[INFO] Processing change of com.abc:hotfix:1.0.10 -> 2.0.2
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.264 s
[INFO] Finished at: 2020-07-13T11:27:41+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.7:set (default-cli) on project fixpack: Execution default-cli of goal org.codehaus.mojo:versions-maven-plugin:2.7: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
如果我暂时删除 Project 文件夹中的父 pom.xml,它工作正常。我的目标是在 pom_hotfix.xml 中增加版本。我不知道为什么我会收到一个空指针。