有时,从构建机器到远程存储库的网络质量并不完美。当然,改善网络将是最好的解决方案,但并不总是可行的。
有一些策略可以解决网络问题。
部署插件提供retryFailedDeploymentCount参数以在放弃并返回部署目标失败之前多次重试部署:
<project> [...] <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <configuration> <retryFailedDeploymentCount>3</retryFailedDeploymentCount> <configuration> </plugin> </plugins> </build> [...] </project>
当网络确实不一致时,更深层次的策略是分2步部署:
1.在构建过程中部署到本地目录,例如file:./target/staging-deploy,
2.然后从本地复制到目标远程存储库,尽可能多地重试。
可以从命令行部署到本地目录,无需更改 POM,使用altDeploymentRepository参数:
mvn deploy -DaltDeploymentRepository=local::file:./target/staging-deploy
或者对于 maven-deploy-plugin 的旧 2.x 版本
mvn deploy -DaltDeploymentRepository=local::default::file:./target/staging-deploy
当然,如果您想从临时策略变为通用策略,您可以在pom.xml中配置存储库。
wagon-maven-plugin的merge-maven-repos目标提供了一种从一个远程存储库复制到另一个远程存储库的机制,同时合并存储库元数据。
wagon-maven-plugin的上传目标将在不处理存储库元数据的情况下执行相同的操作:如果您有一个空存储库作为目标,请使用它,例如存储库管理器提供的暂存存储库。
它可以完全从命令行调用(当Wagon Maven 插件 2.0.1 发布时,用wagon.targetId重命名-Dwagon.):
mvn org.codehaus.mojo:wagon-maven-plugin:2.0.0:merge-maven-repos \ -Dwagon.source=file:./target/staging-deploy \ -Dwagon.target=https://... \ -Dwagon.=id # or once wagon-maven-plugin 2.0.1 is released: -Dwagon.targetId=id
或者更简单地使用mvn wagon:merge-maven-repos并在pom.xml中配置:
<project> [...] <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>wagon-maven-plugin</artifactId> <version>2.0.0</version> <configuration> <source>file:./target/staging-deploy</source> <target>${project.distributionManagement.repository.url}</target> <targetId>${project.distributionManagement.repository.id}</targetId> </configuration> </plugin> </plugins> </build> [...] </project>