If the dependency is a unique snapshot version and install is called, what does maven select?

两盒软妹~` 提交于 2020-01-13 18:57:10

问题


Imagine two projects. The first is the framework-core project which is in version 1.1.0 and has several snapshot builds. The other is the example-business project which has the following dependency to framework-core on the build-iteration number 9.

<dependency>
  <groupId>org.example</groupId>
  <artifactId>framework-core</artifactId>
  <version>1.1.0-20100518.134928-9</version>
</dependency>

What happens if mvn install is called on the framework-core? I found out that the artifact is copied to the folder and is named to *.1.1.0-SNAPSHOT.jar (as expected).

This lead me to the assumption that this version is only used if even this 1.1.0-SNAPSHOT version is defined as dependency and not the precise build.

To test something local without deploying it to the maven repository: call mvn install, change the dependency to 1.1.0-SNAPSHOT -- and the artifact just installed is used? Or is it possible to overwrite the specific build (with using the install lifecycle phase)?


回答1:


When using a dependency with a timestamp version of a -SNAPSHOT - like -20100518.134928-9 in this case - you lock the version and explicitly tell Maven to use this version. Even if a new -SNAPSHOT is build, the dependency won't get updated, that's the point of a "locked snapshot".

If you want to use the latest -SNAPSHOT, declare a dependency on the -SNAPSHOT version to unlock the dependency:

<dependency>
  <groupId>org.example</groupId>
  <artifactId>framework-core</artifactId>
  <version>1.1.0-SNAPSHOT</version>
</dependency>

Changing it manually is not a big deal but the following goals of the Versions Maven plugin might help in some situations:

  • versions:lock-snapshots searches the pom for all -SNAPSHOT versions and replaces them with the current timestamp version of that -SNAPSHOT, e.g. -20090327.172306-4
  • versions:unlock-snapshots searches the pom for all timestamp locked snapshot versions and replaces them with -SNAPSHOT. versions:unlock-snapshots


来源:https://stackoverflow.com/questions/2865296/if-the-dependency-is-a-unique-snapshot-version-and-install-is-called-what-does

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!