有没有办法让Maven自动下载快照版本?
所以我有一个项目依赖于另一个项目的快照版本。依赖关系是:
<dependency>
<groupId>org.oop</groupId>
<artifactId>oop</artifactId>
<version>0.9.9-SNAPSHOT</version>
</dependency>
对于 oop 项目,我确实执行了“mvn clean 部署”,因此快照版本应该位于 Maven 中央存储库中的某个位置。但是,当我执行 mvn clean install 时,无法解决上面的快照依赖项,我得到以下信息:
Missing:
1) org.oop:oop:jar:0.9.9-SNAPSHOT
尝试从项目网站手动下载文件。
然后,使用以下命令安装它: mvn install:install-file -DgroupId=org.oop -DartifactId=oop -Dversion=0.9.9-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file
或者,如果您托管自己的存储库,则可以部署该文件那里: mvn 部署:部署文件 -DgroupId=org.oop -DartifactId=oop -Dversion=0.9.9-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
< strong>有没有办法让maven自动下载快照?我一定在这里遗漏了一些东西。
编辑1:在我的settings.xml中,我有:
<server>
<id>sonatype-nexus-snapshots</id>
<username>XXXXXX</username>
<password>XXXXXX</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>XXXXXX</username>
<password>XXXXXX</password>
</server>
编辑2:
So I have a project that depends on a snapshot version of another project. The dependency is:
<dependency>
<groupId>org.oop</groupId>
<artifactId>oop</artifactId>
<version>0.9.9-SNAPSHOT</version>
</dependency>
For the oop project, I did do a 'mvn clean deploy', so the snapshot version should be somewhere in the maven central repository. But when I do a mvn clean install, the snapshot dependency above cannot be resolved and I get this:
Missing:
1) org.oop:oop:jar:0.9.9-SNAPSHOT
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.oop -DartifactId=oop -Dversion=0.9.9-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=org.oop -DartifactId=oop -Dversion=0.9.9-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Is there a way to make maven download the snapshot automatically? I must be missing something here.
EDIT1: On my settings.xml I have:
<server>
<id>sonatype-nexus-snapshots</id>
<username>XXXXXX</username>
<password>XXXXXX</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>XXXXXX</username>
<password>XXXXXX</password>
</server>
EDIT2:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
只需将其添加到您的 ~/.m2/settings.xml 中:
Just add this to your ~/.m2/settings.xml:
要更新快照,请尝试使用 -U 选项
但是,您说:
这是不可能的,您的快照正在其他地方。如果我在没有配置我的个人存储库的情况下执行
mvn clean deploy
,我会得到:要启用部署,需要在 pom.xml 中添加一些配置,例如:
To update snapshots, try with the -U option
However, you said:
This is just not possible, your snapshot is going somewhere else. If I do a
mvn clean deploy
without configuring my personal repository I get:To enable deployment, there is some configuration to be added to pom.xml, like for instance:
Maven 会尝试自动下载快照,确实如此(如您的错误所示)。默认情况下,Maven 将每天查找一次较新的快照版本,但您可以在快照存储库配置中更改该间隔(例如在 settings.xml 中):
这将使 Maven 每 5 分钟检查一次(如果您经常构建)。或者,您可以使用
-U
或--update-snapshots
选项来强制手动检查。但是,它找不到依赖项。您可以发布快照依赖项的存储库设置和工件配置吗?
您的存储库中是否有 org.oop:oop:jar:0.9.9-SNAPSHOT 工件?
不,不是。我试图查找它,但找不到。 Afaik,有一些暂存机制,所以也许您的设置是错误的。但通常情况下,正如其他人已经说过的,您会使用自己的存储库管理器,例如 Artifactory 或 Nexus。
Maven would try to download the snapshot automatically and indeed it does (as your error indicates). By default, Maven will look for newer snapshot versions once a day, but you can change that interval in your snapshot repository config (e.g. in settings.xml):
This will make maven check every 5 minutes (if you build that often). Alternatively, you could use the
-U
or--update-snapshots
option, to force the check manually.However, it can't find the dependency. Could you post your repo settings and artifact config for the snapshot dependency?
Is the
org.oop:oop:jar:0.9.9-SNAPSHOT
artifact in your repository?No it isn't. I tried to look it up, but couldn't find it. Afaik, there's some staging mechanism, so maybe your settings are just wrong. But normally, as the others already said, you'd go and use your own repository manager like Artifactory or Nexus.
您的存储库中是否存在该依赖项? (在 pom.xml 或 settings.xml 中)?
看起来不是。顺便说一句,看看你的配置,只是你没有使用
-o
(离线)。您还可以使用-U
刷新快照。Does that dependency exists in your repository? (in pom.xml or settings.xml)?
Looks like not. By the way, take a look at your config, just you are not using
-o
(offline). Also you can use-U
to refresh snapshots.您可以
You can either
让我们稍微澄清一下术语,以确保不会产生误解。
“Maven Central”(http://search.maven.org/)是一个全球站点,您只能在其中找到发布。 Central 不接受快照,因此在那里部署应该会出现错误。
您可能指的是您的本地/公司范围的 Maven 代理/缓存。这些也可以配置为拒绝快照版本。对于 Nexus,您还可以定义更复杂的规则。就我而言,我遇到了一个问题,在
mvn部署
期间没有给出错误,但我可以在服务器日志中看到错误。尝试跟踪数据:启用调试(
mvn -X
)以查看 Maven 将数据上传到哪里。然后检查服务器以查看工件是否真的上传。检查服务器日志是否有错误。另请注意,快照依赖项每天仅刷新一次;所以这行不通:
PC #1:
mvn install
->错误缺少依赖项PC #2:
mvn 部署
PC #1:
mvn install
->由于“每天更新一次”策略,依赖关系仍然丢失尝试
mvn install -U
强制 Maven 刷新其缓存的元数据。Let's clear up terminology a bit to make sure there is no misunderstanding.
"Maven Central" (http://search.maven.org/) is a global site where you only find releases. Central doesn't accept snapshots so deploying there should give you an error.
You probably mean your local/company wide maven proxy/cache. These can also be configured to reject snapshot versions. In case of Nexus, you can also define more complex rules. In my case, I had an issue there which gave no error during
mvn deploy
but I could see an error in the server's logs.Try to follow the data: Enable debug (
mvn -X
) to see where Maven uploads the data. Then check the server to see whether the artifacts were really uploaded. Check the server's logs for errors.Also note that snapshot dependencies are only refreshed once a day; so this won't work:
PC #1:
mvn install
-> Error missing dependencyPC #2:
mvn deploy
PC #1:
mvn install
-> Dependency is still missing because of "update once per day" policyTry
mvn install -U
to force Maven to refresh its cached metadata.即使在命令行上设置 -U,我也遇到了快照不更新的问题。对我来说,问题是我的客户端是 Maven 3,服务器是 Maven 2,并且在 Maven 3 中不再支持唯一快照。我们必须创建一个带有时间戳快照的新存储库来支持 3.xx 客户端。
I hit the issue of snapshots not updating even when setting -U on the command line. For me the issue was my client was Maven 3 and the server was Maven 2, and in Maven 3 unique snapshots are no longer supported. We had to create a new repository with timestamped snapshots to support the 3.xx clients.