为什么 Maven 会多次下载同一个工件?
Why is maven downloading the same artifact multiple times?
我 运行 一个 maven 构建,我看到同一个工件被下载了好几次。从一个存储库成功下载后,将尝试从另一个存储库下载。一些下载是 (0 B at 0.0 KB/sec).
[INFO] Downloading: https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (5 KB at 59.8 KB/sec)
[INFO] Downloading: https://p-nexus.mycompany.com/nexus/content/repositories/public/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/public/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (0 B at 0.0 KB/sec)
[INFO] Downloading: http://repo.spring.io/ext-release-local/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloading: http://repo.spring.io/milestone/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloading: http://repo.spring.io/snapshot/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
存储库配置:
<repositories>
<repository>
<id>Myproject-group</id>
<name>Myproject-group</name>
<layout>default</layout>
<url>https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/</url>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
</repository>
</repositories>
不是多次下载。它无法在第一个存储库中找到它,因此它正在尝试您的 <repositories/>
列表中的下一个。
您可以通过让 Maven 镜像所有存储库请求来强制它使用单个存储库。存储库必须包含所有需要的工件,或者能够将请求代理到其他存储库。当使用带有 Maven 存储库管理器的内部公司存储库来代理外部请求时,此设置最有用。
为此,将 mirrorOf 设置为 *.
<settings>
...
<mirrors>
<mirror>
<id>internal-repository</id>
<name>Maven Repository Manager running on repo.mycompany.com</name>
<url>http://repo.mycompany.com/proxy</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
更多详情here
希望这对您有所帮助。
查看日志信息,会发现多次下载都没有。
[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (5 KB at 59.8 KB/sec)
[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/public/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (0 B at 0.0 KB/sec)
如您所见,它们的路径不同,即使 jar 文件相同并且在第二个 INFO 的末尾,它显示 0 B at 0.0 KB/sec
这意味着它没有下载。
我 运行 一个 maven 构建,我看到同一个工件被下载了好几次。从一个存储库成功下载后,将尝试从另一个存储库下载。一些下载是 (0 B at 0.0 KB/sec).
[INFO] Downloading: https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (5 KB at 59.8 KB/sec)
[INFO] Downloading: https://p-nexus.mycompany.com/nexus/content/repositories/public/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/public/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (0 B at 0.0 KB/sec)
[INFO] Downloading: http://repo.spring.io/ext-release-local/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloading: http://repo.spring.io/milestone/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
[INFO] Downloading: http://repo.spring.io/snapshot/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
存储库配置:
<repositories>
<repository>
<id>Myproject-group</id>
<name>Myproject-group</name>
<layout>default</layout>
<url>https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/</url>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
</repository>
</repositories>
不是多次下载。它无法在第一个存储库中找到它,因此它正在尝试您的 <repositories/>
列表中的下一个。
您可以通过让 Maven 镜像所有存储库请求来强制它使用单个存储库。存储库必须包含所有需要的工件,或者能够将请求代理到其他存储库。当使用带有 Maven 存储库管理器的内部公司存储库来代理外部请求时,此设置最有用。
为此,将 mirrorOf 设置为 *.
<settings>
...
<mirrors>
<mirror>
<id>internal-repository</id>
<name>Maven Repository Manager running on repo.mycompany.com</name>
<url>http://repo.mycompany.com/proxy</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
...
</settings>
更多详情here
希望这对您有所帮助。
查看日志信息,会发现多次下载都没有。
[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/Myproject-group/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (5 KB at 59.8 KB/sec)
[INFO] Downloaded: https://p-nexus.mycompany.com/nexus/content/repositories/public/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (0 B at 0.0 KB/sec)
如您所见,它们的路径不同,即使 jar 文件相同并且在第二个 INFO 的末尾,它显示 0 B at 0.0 KB/sec
这意味着它没有下载。