If the dependency is a unique snapshot version and install is called, what does maven select?
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 th开发者_运维技巧e 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)?
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-4versions:unlock-snapshots
searches the pom for all timestamp locked snapshot versions and replaces them with -SNAPSHOT. versions:unlock-snapshots
精彩评论