Maven 多项目打包中,${reversion} 变量未替换,如何解决?
解决 maven 多项目打包中 ${reversion} 未替换问题
在使用 maven 管理多项目时,遇到如下打包错误:
failed to read artifact descriptor for com.example:c2:jar:1.0.0-snapshot: failure to find com.example:packagetest:pom:${reversion} in <a href="http://xxxx/repository/maven-public/" target="_blank">http://xxxx/repository/maven-public/</a> was cached in the local repository, resolution will not be reattempted until the update interval of nexus-repo has elapsed or updates are forced -> [help 1]
原因是父项目中使用 ${reversion} 作为版本变量,子项目在打包时无法在本地仓库中找到匹配的父项目 pom 文件。
解决方法是:
- 在父项目中直接设置版本号
例如:
<project> <groupid>com.example</groupid> <artifactid>packagetest</artifactid> <version>1.0.0-snapshot</version> </project>
- 使用 maven 插件批量更新版本号
可以使用 maven-release-plugin 插件批量更新子项目的父项目版本号:
<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-release-plugin</artifactid> <version>3.1.2</version> <configuration> <developmentversion>1.0.0-snapshot</developmentversion> </configuration> </plugin>
maven 官方对于 relativepath 的解释:
The relative path of the parent pom.xml file within the check out. If not specified, it defaults to ../pom.xml. Maven looks for the parent POM first in this location on the filesystem, then the local repository, and lastly in the remote repo. relativePath allows you to select a different location, for example when your structure is flat, or deeper without an intermediate parent POM. However, the group ID, artifact ID and version are still required, and must match the file in the location given or it will revert to the repository for the POM. This feature is only for enhancing the development in a local checkout of that project. Set the value to an empty string in case you want to disable the feature and always resolve the parent POM from the repositories. Default value is: ../pom.xml.
以上就是Maven 多项目打包中,${reversion} 变量未替换,如何解决?的详细内容,更多请关注其它相关文章!