登录
首页 >  文章 >  java教程

Maven 多项目打包中,${reversion} 变量未替换,如何解决?

时间:2024-11-23 19:51:05 120浏览 收藏

一分耕耘,一分收获!既然打开了这篇文章《Maven 多项目打包中,${reversion} 变量未替换,如何解决?》,就坚持看下去吧!文中内容包含等等知识点...希望你能在阅读本文后,能真真实实学到知识或者帮你解决心中的疑惑,也欢迎大佬或者新人朋友们多留言评论,多给建议!谢谢!

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 -&gt; [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} 变量未替换,如何解决?》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

相关阅读
更多>
最新阅读
更多>
课程推荐
更多>