Maven specific version of a snapshot dependency

2020-02-08 23:33发布

Is there a way to get Maven to download a specific snapshot version of a dependency? I know that specifying the dependency like this will download the lastest snapshot available:

<dependency>
<groupId>groupid</groupId>
<artifactId>artifact-id</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>

Is it possible to specify a specific snapshot version? (e.g.artifact-id-1.0.0-20090610.041042-5) This would be useful if the head snapshot build has broken something and the stable version of the dependency has yet to be officially released.

标签: maven-2
4条回答
爷的心禁止访问
2楼-- · 2020-02-08 23:50

AFAIK the SNAPSHOT always refers to the latest build and there is no way to depend on specific version.

To work around this issue, you could republish the exact version you want to depend on in your own maven repository and assign it a specific version.

查看更多
Summer. ? 凉城
3楼-- · 2020-02-08 23:53

Yes, you can. Any version that is in your maven repositories can be used. I've ran into some problems where the trasnsitive dependencies mucked with the version though. That's where mvn dependency:tree came in handy.

查看更多
叛逆
5楼-- · 2020-02-09 00:03

To use a specific snapshot version of a dependency, the referenced artifact should be installed/deployed with a unique snapshot version number. See the uniqueVersion element in the POM reference/Repository. In this case you can reference it like:

...
<dependency>
<groupId>groupid</groupId>
<artifactId>artifact-id</artifactId>
<version>1.0.0-20090610.041042-5</version>
</dependency>
...

Maven repository manager servers may have additional related features, like overriding the pom.xml's uniqueVersion setting. For example see the Artifactory User Guide about this feature (additionally, you can read here some arguments against using unique snapshot version numbers).

查看更多
登录 后发表回答