我正在使用Apache Maven构建我的项目,并配置了一个自定义存储库,但是当它访问存储库时,它会挂起很长一段时间
下载:http://maven.mycompany.com/m2/org/springframework/spring/2.5.6/spring-2.5.6.pom
几分钟后,它会从中央存储库下载它
下载:已下载http://repo1.maven.org/maven2/org/springframework/spring/2.5.6/spring-2.5.6.pom 12K (spring-2.5.6.pom)
我希望超时时间比这快得多。所有较新版本的maven都会发生这种情况。2.0.6或更早的版本没有这个问题,它会更快地超时。
发布于 2009-07-22 22:04:14
在Maven 2.1之前的版本中,无法将客户端配置为超时,但如果设置了更新策略,则可以将其配置为检查更新的频率较低。这部分解决了这个问题。
例如:
<repository>
<id>myrepo</id>
<url>http://maven.mycompany.com/m2</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
有效值包括:
Maven
另一个考虑因素是您用来托管内部存储库的软件。使用诸如Nexus之类的存储库管理器,您可以通过该管理器管理所有外部远程存储库连接,并为这些远程连接配置超时。然后,您的客户端将只查询存储库管理器,该管理器应在超时允许的情况下尽可能快地响应。
更新:
如果您知道依赖关系不会由特定的存储库提供服务,您可以将其分离到一个配置文件中,这样它就不会在该构建中被引用。
<profiles>
<profile>
<id>remote</id>
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
...
</repositories>
</profile>
<profile>
<id>internal</id>
<repositories>
<repository>
<id>myrepo</id>
<url>http://maven.mycompany.com/m2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
...
</repositories>
</profile>
</profiles>
使用上面的配置,运行mvn package -Premote将不会连接到内部存储库,因此超时不会成为一个因素。
通过将一些额外的配置添加到您的设置中,可以避免在每次构建时指定配置文件:
<settings>
...
<activeProfiles>
<activeProfile>internal</activeProfile>
<activeProfile>remote</activeProfile>
</activeProfiles>
...
</settings>
对于Maven2.1,您可以通过在Maven设置(默认情况下为~/.m2/settings.xml
)中添加服务器上的配置来设置超时,例如:
<server>
<id>myrepo</id>
<configuration>
<timeout>5000</timeout> <!-- 5 seconds -->
</configuration>
</server>
发布于 2013-03-15 01:44:15
一种快速而肮脏的方法是添加自定义主机文件条目,以将对无效存储库的网络请求重定向到有效存储库。
https://stackoverflow.com/questions/1168468
复制相似问题