Java Maven 无法从存储库获取 SNAPSHOT 构建
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4097445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven fails to get SNAPSHOT builds from repository
提问by Kris
Our internal repository (Artifactory) now contains both the stable builds as well as SNAPSHOT versions of our internal libraries.
我们的内部存储库 (Artifactory) 现在包含我们内部库的稳定版本和 SNAPSHOT 版本。
For stable builds there has never been a problem of downloading anything from the repository.
对于稳定的构建,从存储库下载任何东西从来没有问题。
However, when I add a -SNAPSHOT, Maven claims to be unable to find the dependency, even though it is most definitely in the repository.
但是,当我添加 -SNAPSHOT 时,Maven 声称无法找到依赖项,即使它绝对在存储库中。
If I build and deploy the dependency locally (i.e. into my local repo) all works normally.
如果我在本地构建和部署依赖项(即到我的本地仓库),一切正常。
Basically, this works:
基本上,这有效:
<dependency>
<groupId>com.example</groupId>
<artifactId>ourlibrary</artifactId>
<version>1.0.0</version>
</dependency>
and this doesn't:
而这不会:
<dependency>
<groupId>com.example</groupId>
<artifactId>ourlibrary</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
Even though both versions were built the same way and deployed (as far as I can possibly tell) correctly to the repository.
即使两个版本都以相同的方式构建并正确部署(据我所知)到存储库。
The error:
错误:
Missing:
----------
1) com.example:ourlibrary:jar:1.0.1-SNAPSHOT,
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.example -DartifactId=ourlibrary -Dversion=1.0.1-SNAPSHOT, -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=com.example -DartifactId=ourlibrary -Dversion=1.0.1-SNAPSHOT, -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) com.example:product:war:2.0.0-SNAPSHOT
2) com.example:ourlibrary:jar:1.0.1-SNAPSHOT,
While this sounds similar to thisquestion, the resolution arrived at there does not apply to my case.
虽然这听起来与这个问题相似,但在那里达成的决议并不适用于我的情况。
Any insights into this issue would be greatly appreciated.
对这个问题的任何见解将不胜感激。
Edit
编辑
Running with -X (as John V. suggested) revealed the following:
使用 -X 运行(如 John V. 建议的)显示以下内容:
[DEBUG] Skipping disabled repository central
[DEBUG] ourlibrary: using locally installed snapshot
[DEBUG] Skipping disabled repository central
[DEBUG] Using mirror: http://repo.example.com/repo (id: repo.example.com)
[DEBUG] Artifact not found - using stub model: Unable to download the artifact from any repository
com.example:ourlibrary:pom:1.0.1-SNAPSHOT
from the specified remote repositories:
repo.example.com (http://repo.example.com/repo)
[DEBUG] Using defaults for missing POM com.example:ourlibrary:pom:1.0.1-SNAPSHOT:compile
[DEBUG] com.example:ourlibrary:jar:1.0.1-SNAPSHOT:compile (selected for compile)
采纳答案by John Vint
Two thoughts come to mind:
想到两个想法:
The path structure in your internal repository for your artifact is incorrect. I suggest running the maven command with -X parameter. It will display the maven's attempt at downloading the files. Get the line that has your repository as the url and try and look for it yourself.
The path should look like
/com/example/ourlibrary/1.0.1/ourlibrary-1.0.1-SNAPSHOT.jar
- You didnt include your repository as a repository in your pom.xml
您的工件的内部存储库中的路径结构不正确。我建议使用 -X 参数运行 maven 命令。它将显示 Maven 尝试下载文件。获取将您的存储库作为 url 的行并尝试自己查找。
路径应该看起来像
/com/example/ourlibrary/1.0.1/ourlibrary-1.0.1-SNAPSHOT.jar
- 您没有将您的存储库作为存储库包含在您的 pom.xml 中
回答by kevinmrohr
Typically you have a separate snapshots url from releases url. Just different paths in the same repository, but listed as separate repositories in the pom. The one for snapshots needs to have snapshots enabled, and the one for releases has snapshots disabled:
通常,您有一个与发布 url 不同的快照 url。只是同一存储库中的不同路径,但在 pom.xml 中列为单独的存储库。一个用于快照的需要启用快照,一个用于发布的需要禁用快照:
<repositories>
<repository>
<id>central</id>
<url>
http://<releases-url>
</url>
**<snapshots>
<enabled>false</enabled>
</snapshots>**
</repository>
<repository>
<id>snapshots</id>
<url>
http://<snapshots-url>
</url>
<snapshots>
**<enabled>true</enabled>**
<!-- never, daily, interval:X (where X is in minutes) or always -->
<!--<updatePolicy>daily</updatePolicy> -->
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>