我们在我们的环境中运行了一个 Sonatype Nexus,其中配置了另一个 Nexus 作为代理存储库。当我们使用我们的依赖项时,我们会向我们的 Nexus 询问它们。这一直很好,直到昨天我向我们的项目添加了一个新的依赖项。
Maven 似乎没有正确解析部署的快照版本。在 maven 日志中,我可以看到它正在下载 maven-metadata.xml 但是当它尝试下载包含我们的二进制文件的 zip 文件时,它不会用当前快照版本替换 -SNAPSHOT
> mvn -f My.Product.dependencies.xml process-resources -DConfiguration=AnyConfig -U -X
[DEBUG] Could not find metadata com.company.team:My.New.Dependency:2.2-SNAPSHOT/maven-metadata.xml in local (d:\Maven\repositories)
[DEBUG] Using connector WagonRepositoryConnector with priority 0 for http://buildserver:8082/nexus/content/groups/company
Downloading: http://buildserver:8082/nexus/content/groups/company/com/company/team/My.New.Dependency/2.2-SNAPSHOT/maven-metadata.xml
Downloaded: http://buildserver:8082/nexus/content/groups/company/com/company/team/My.New.Dependency/2.2-SNAPSHOT/maven-metadata.xml (850 B at 13.2 KB/sec)
[DEBUG] Reading resolution tracking file d:\Maven\repositories\com\company\team\My.New.Dependency\2.2-SNAPSHOT\resolver-status.properties
[DEBUG] Writing resolution tracking file d:\Maven\repositories\com\company\team\My.New.Dependency\2.2-SNAPSHOT\resolver-status.properties
[DEBUG] Could not find metadata com.company.team:My.New.Dependency:2.2-SNAPSHOT/maven-metadata.xml in local (d:\Maven\repositories)
[DEBUG] Using connector WagonRepositoryConnector with priority 0 for http://buildserver:8082/nexus/content/groups/company
Downloading: http://buildserver:8082/nexus/content/groups/company/com/company/team/My.New.Dependency/2.2-SNAPSHOT/maven-metadata.xml
Downloaded: http://buildserver:8082/nexus/content/groups/company/com/company/team/My.New.Dependency/2.2-SNAPSHOT/maven-metadata.xml (850 B at 55.3 KB/sec)
[DEBUG] Reading resolution tracking file d:\Maven\repositories\com\company\team\My.New.Dependency\2.2-SNAPSHOT\resolver-status.properties
[DEBUG] Writing resolution tracking file d:\Maven\repositories\com\company\team\My.New.Dependency\2.2-SNAPSHOT\resolver-status.properties
...
Downloading: http://buildserver:8082/nexus/content/groups/company/com/company/team/My.New.Dependency/2.2-SNAPSHOT/My.New.Dependency-2.2-SNAPSHOT-vs2010-40-AnyCpu-Release.zip
[DEBUG] Reading resolution tracking file d:\Maven\repositories\com\company\team\My.New.Dependency\2.2-SNAPSHOT\My.New.Dependency-2.2-SNAPSHOT-vs2010-40-AnyCpu-Release.zip.lastUpdated
[DEBUG] Writing resolution tracking file d:\Maven\repositories\com\company\team\My.New.Dependency\2.2-SNAPSHOT\My.New.Dependency-2.2-SNAPSHOT-vs2010-40-AnyCpu-Release.zip.lastUpdated
[INFO] ------------------------------------------------------------------------
...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] My.Client.App FAILURE [1.922s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.687s
[INFO] Finished at: Thu Oct 13 09:54:24 CEST 2016
[INFO] Final Memory: 9M/177M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project My.Client.App: Could not resolve dependencies for project com.company.team2:My.Client.App:pom:7.0-SNAPSHOT: The following artifacts could not be resolved: com.company.team:My.New.Dependency:zip:vs2010-40-AnyCpu-Release:2.2-SNAPSHOT: Could not find artifact com.company.team:My.New.Dependency:zip:vs2010-40-AnyCpu-Release:2.2-SNAPSHOT in company (http://buildserver:8082/nexus/content/groups/company) -> [Help 1]
maven-metadata.xml 正确包含快照版本信息:
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
<groupId>com.company.team</groupId>
<artifactId>My.New.Dependency</artifactId>
<version>2.2-SNAPSHOT</version>
<versioning>
<snapshot>
<timestamp>20161011.235855</timestamp>
<buildNumber>102</buildNumber>
</snapshot>
<lastUpdated>20161011235855</lastUpdated>
<snapshotVersions>
<snapshotVersion>
<extension>pom</extension>
<value>2.2-20161011.235855-102</value>
<updated>20161011235855</updated>
</snapshotVersion>
<snapshotVersion>
<classifier>vs2010-40-AnyCPU-Release</classifier>
<extension>zip</extension>
<value>2.2-20161011.235855-102</value>
<updated>20161011235855</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>
</metadata>
当我检查从中下载内容的文件夹的目录列表时,2.2-20161011.235855-102 版本正确存在:
来自同一存储库的所有其他依赖项都可以正常工作,只是没有下载新引入的依赖项。目前让我抓狂的是 Maven 没有像对所有其他依赖项那样用实际的快照版本号替换 -SNAPSHOT。我还尝试了 Nexus UI 中的“过期缓存”和“更新索引”选项,但这并没有帮助。什么可能导致 Maven 从实际版本号回退到 -SNAPSHOT?也没有日志条目可以解释这一点。