Maven: To get latest release mvn clean then mvn package working fine but mvn clean package not

huangapple go评论61阅读模式
英文:

Maven: To get latest release mvn clean then mvn package working fine but mvn clean package not

问题

我有一个单项目设置,在其中我正在使用 versions-maven-plugin 来获取最新的发布版本。

当我在运行 mvn package 之前运行 mvn clean,会收到更新的消息,其中指定了:

[INFO] 将 old_version:jar:0 更新为新版本 new_version。

但是当我同时运行 mvn clean package 时,Maven 无法获取最新版本,我收到了这个错误消息:

找不到 artifact old_version:jar:0

为什么会发生这种情况?如果 Maven 遵循执行顺序,那么它应该先执行清理以更新版本,然后再打包。有没有关于为什么 mvn clean package 命令不起作用的任何想法?

英文:

I have single project setup where I am using versions-maven-plugin to get latest release.

When I ran mvn clean before mvn package, getting updated message which specify

[INFO] Updated old_version:jar:0 to version new_version.

But when I ran mvn clean package together then maven not able to get latest version and I got this error message

Could not find artifact old_version:jar:0

Why is this happening? If maven follows the order of execution then it should clean which updates the version first then package.
Any idea why mvn clean package command is not working.

答案1

得分: 1

运行 mvn clean,然后再运行 mvn package,与直接运行 mvn clean package 不完全相同。

原因:Maven 在运行任何生命周期之前会先解析所有的依赖关系。

因此,如果你先运行 mvn clean,然后再运行 mvn package,你会得到:

  • 解析依赖关系
  • 更新你的依赖
  • 解析依赖关系
  • 打包

但是如果你直接运行 mvn clean package,你会得到:

  • 解析依赖关系
  • 更新你的依赖
  • 打包(使用了从一开始就解析的依赖关系)

总结:你不能在同一次 Maven 运行中更新并使用依赖关系。

英文:

Running mvn clean and then mvn package is not exactly the same as mvn clean package.

The reason: Maven resolves all dependencies before it runs any of the lifecycles.

So if you run mvn clean and then mvn package you get:

  • resolves dependencies
  • updates your dependecy
  • resolves dependencies
  • package

but if you run mvn clean package, you get:

  • resolves dependencies
  • updates your dependency
  • package (with the resolved dependencies from the beginning)

Summarized: You cannot update and use dependencies in the same Maven run.

huangapple
  • 本文由 发表于 2020年9月24日 15:38:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/64041632.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定