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:
对于oop项目,我确实进行了“mvn clean deploy”,因此快照版本应该位于maven*存储库中的某个位置。但是当我进行mvn clean安装时,上面的快照依赖项无法解决,我得到了这个:
Missing:
失踪:
1) org.oop:oop:jar:0.9.9-SNAPSHOT
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
然后,使用以下命令安装它: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]
或者,如果您托管自己的存储库,则可以在那里部署文件: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.
有没有办法让maven自动下载快照?我必须在这里遗漏一些东西。
EDIT1: On my settings.xml I have:
EDIT1:在我的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>
EDIT2:
EDIT2:
7 个解决方案
#1
16
Just add this to your ~/.m2/settings.xml:
只需将其添加到〜/ .m2 / settings.xml:
<profiles>
<profile>
<id>allow-snapshots</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>
#2
19
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):
Maven会尝试自动下载快照,实际上也是如此(正如您的错误所示)。默认情况下,Maven将每天查找一次较新的快照版本,但您可以在快照存储库配置中更改该间隔(例如,在settings.xml中):
<updatePolicy>interval:5</updatePolicy>
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.
这将使maven每5分钟检查一次(如果你经常建立)。或者,您可以使用-U或--update-snapshots选项手动强制检查。
However, it can't find the dependency. Could you post your repo settings and artifact config for the snapshot dependency?
但是,它无法找到依赖关系。你能为快照依赖发布你的repo设置和工件配置吗?
Is the org.oop:oop:jar:0.9.9-SNAPSHOT
artifact in your repository?
您的存储库中是org.oop:oop:jar:0.9.9-SNAPSHOT工件吗?
... so the snapshot version should be somewhere in the maven central repository.
...所以快照版本应该在maven*存储库中的某个位置。
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.
不,不是。我试着查一查,但找不到它。 Afaik,有一些升级机制,所以也许你的设置是错的。但通常情况下,正如其他人已经说过的那样,您可以使用自己的存储库管理器,如Artifactory或Nexus。
#3
15
To update snapshots, try with the -U option
要更新快照,请尝试使用-U选项
-U,--update-snapshots Forces a check for updated
releases and snapshots on remote
repositories
However, you said:
但是,你说:
I did do a 'mvn clean deploy', so the snapshot version should be somewhere in the maven central repository.
我确实做了'mvn clean deploy',因此快照版本应该位于maven*存储库中的某个位置。
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:
这是不可能的,你的快照正在其他地方。如果我在没有配置我的个人存储库的情况下进行mvn clean部署,我会得到:
Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
部署失败:未在分配管理元素中的POM或-DaltDeploymentRepository = id :: layout :: url参数中指定存储库元素
To enable deployment, there is some configuration to be added to pom.xml, like for instance:
要启用部署,需要将一些配置添加到pom.xml,例如:
<distributionManagement>
<!-- Publish versioned releases here -->
<repository>
<id>myrepo</id>
<name>My releases</name>
<url>http://nexus.mycompany.com/nexus/content/repositories/releases</url>
</repository>
<!-- Publish snapshots here -->
<snapshotRepository>
<id>myrepo</id>
<name>my snapshots</name>
<url>http://nexus.mycompany.com/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>myrepo</id>
<name>My Public Repository</name>
<url>http://nexus.mycompany.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
#4
1
Does that dependency exists in your repository? (in pom.xml or settings.xml)?
您的存储库中是否存在该依赖项? (在pom.xml或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.
看起来不是。顺便说一句,看看你的配置,只是你没有使用-o(离线)。您也可以使用-U刷新快照。
#5
0
You can either
你也可以
- use a parent project which builds all your snapshots, or
- 使用构建所有快照的父项目,或
- deploy your snapshots to your maven build server (nexus/archiva/..) using e.g., mvn:deploy
- 使用例如mvn:deploy将您的快照部署到您的maven构建服务器(nexus / archiva / ..)
#6
0
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.
“Maven Central”(http://search.maven.org/)是一个全球网站,您只能在其中找到版本。 Central不接受快照,因此在那里部署应该会给您一个错误。
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.
您可能意味着您的本地/公司范围的maven代理/缓存。这些也可以配置为拒绝快照版本。对于Nexus,您还可以定义更复杂的规则。在我的情况下,我有一个问题,在mvn部署期间没有出错,但我可以在服务器的日志中看到错误。
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.
尝试关注数据:启用调试(mvn -X)以查看Maven上传数据的位置。然后检查服务器以查看工件是否真正上传。检查服务器的日志以查找错误。
Also note that snapshot dependencies are only refreshed once a day; so this won't work:
另请注意,快照依赖项每天只刷新一次;所以这不会起作用:
PC #1: mvn install
-> Error missing dependency PC #2: mvn deploy
PC #1: mvn install
-> Dependency is still missing because of "update once per day" policy
PC#1:mvn install - >错误缺少依赖PC#2:mvn deploy PC#1:mvn install - >由于“每天更新一次”策略,依赖性仍然缺失
Try mvn install -U
to force Maven to refresh its cached metadata.
尝试使用mvn install -U强制Maven刷新其缓存的元数据。
#7
0
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.
即使在命令行上设置-U,我也遇到了不更新快照的问题。对我来说,问题是我的客户端是Maven 3,服务器是Maven 2,而在Maven 3中不再支持独特的快照。我们必须创建一个带有带时间戳的快照的新存储库来支持3.xx客户端。
#1
16
Just add this to your ~/.m2/settings.xml:
只需将其添加到〜/ .m2 / settings.xml:
<profiles>
<profile>
<id>allow-snapshots</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>
#2
19
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):
Maven会尝试自动下载快照,实际上也是如此(正如您的错误所示)。默认情况下,Maven将每天查找一次较新的快照版本,但您可以在快照存储库配置中更改该间隔(例如,在settings.xml中):
<updatePolicy>interval:5</updatePolicy>
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.
这将使maven每5分钟检查一次(如果你经常建立)。或者,您可以使用-U或--update-snapshots选项手动强制检查。
However, it can't find the dependency. Could you post your repo settings and artifact config for the snapshot dependency?
但是,它无法找到依赖关系。你能为快照依赖发布你的repo设置和工件配置吗?
Is the org.oop:oop:jar:0.9.9-SNAPSHOT
artifact in your repository?
您的存储库中是org.oop:oop:jar:0.9.9-SNAPSHOT工件吗?
... so the snapshot version should be somewhere in the maven central repository.
...所以快照版本应该在maven*存储库中的某个位置。
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.
不,不是。我试着查一查,但找不到它。 Afaik,有一些升级机制,所以也许你的设置是错的。但通常情况下,正如其他人已经说过的那样,您可以使用自己的存储库管理器,如Artifactory或Nexus。
#3
15
To update snapshots, try with the -U option
要更新快照,请尝试使用-U选项
-U,--update-snapshots Forces a check for updated
releases and snapshots on remote
repositories
However, you said:
但是,你说:
I did do a 'mvn clean deploy', so the snapshot version should be somewhere in the maven central repository.
我确实做了'mvn clean deploy',因此快照版本应该位于maven*存储库中的某个位置。
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:
这是不可能的,你的快照正在其他地方。如果我在没有配置我的个人存储库的情况下进行mvn clean部署,我会得到:
Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
部署失败:未在分配管理元素中的POM或-DaltDeploymentRepository = id :: layout :: url参数中指定存储库元素
To enable deployment, there is some configuration to be added to pom.xml, like for instance:
要启用部署,需要将一些配置添加到pom.xml,例如:
<distributionManagement>
<!-- Publish versioned releases here -->
<repository>
<id>myrepo</id>
<name>My releases</name>
<url>http://nexus.mycompany.com/nexus/content/repositories/releases</url>
</repository>
<!-- Publish snapshots here -->
<snapshotRepository>
<id>myrepo</id>
<name>my snapshots</name>
<url>http://nexus.mycompany.com/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>myrepo</id>
<name>My Public Repository</name>
<url>http://nexus.mycompany.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
#4
1
Does that dependency exists in your repository? (in pom.xml or settings.xml)?
您的存储库中是否存在该依赖项? (在pom.xml或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.
看起来不是。顺便说一句,看看你的配置,只是你没有使用-o(离线)。您也可以使用-U刷新快照。
#5
0
You can either
你也可以
- use a parent project which builds all your snapshots, or
- 使用构建所有快照的父项目,或
- deploy your snapshots to your maven build server (nexus/archiva/..) using e.g., mvn:deploy
- 使用例如mvn:deploy将您的快照部署到您的maven构建服务器(nexus / archiva / ..)
#6
0
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.
“Maven Central”(http://search.maven.org/)是一个全球网站,您只能在其中找到版本。 Central不接受快照,因此在那里部署应该会给您一个错误。
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.
您可能意味着您的本地/公司范围的maven代理/缓存。这些也可以配置为拒绝快照版本。对于Nexus,您还可以定义更复杂的规则。在我的情况下,我有一个问题,在mvn部署期间没有出错,但我可以在服务器的日志中看到错误。
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.
尝试关注数据:启用调试(mvn -X)以查看Maven上传数据的位置。然后检查服务器以查看工件是否真正上传。检查服务器的日志以查找错误。
Also note that snapshot dependencies are only refreshed once a day; so this won't work:
另请注意,快照依赖项每天只刷新一次;所以这不会起作用:
PC #1: mvn install
-> Error missing dependency PC #2: mvn deploy
PC #1: mvn install
-> Dependency is still missing because of "update once per day" policy
PC#1:mvn install - >错误缺少依赖PC#2:mvn deploy PC#1:mvn install - >由于“每天更新一次”策略,依赖性仍然缺失
Try mvn install -U
to force Maven to refresh its cached metadata.
尝试使用mvn install -U强制Maven刷新其缓存的元数据。
#7
0
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.
即使在命令行上设置-U,我也遇到了不更新快照的问题。对我来说,问题是我的客户端是Maven 3,服务器是Maven 2,而在Maven 3中不再支持独特的快照。我们必须创建一个带有带时间戳的快照的新存储库来支持3.xx客户端。