执行mvn clean deploy时Pom可上传至Nexus 3但Jar文件上传失败
问题描述
我有一个简单的Spring Boot应用,执行mvn clean deploy部署至Nexus仓库时,打包后的Pom文件成功上传,但Jar文件上传失败。已尝试在Pom中添加<packaging>jar</packaging>标签,问题仍未解决。开启Maven debug模式后,得到以下关键错误:
调试日志异常:
[DEBUG] Failed to dispatch transfer event 'PUT PROGRESSED http://IP-ADDRESS/repository/billing-snapshots/org/billing/billing-service/0.0.1-SNAPSHOT/billing-service-0.0.1-20240305.220831-1.jar <> C:\Users\ergai\Desktop\devops-digital-oceans-projects\billing-service\target\billing-service-0.0.1-SNAPSHOT.jar' to org.apache.maven.cli.transfer.ConsoleMavenTransferListener java.lang.IllegalArgumentException: progressed file size cannot be greater than size: 64430080 > 22686224
核心错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.1.1:deploy (default-deploy) on project billing-service: Failed to deploy artifacts: Could not transfer artifact org.billing:billing-service:jar:0.0.1-20240305.221751-1 from/to nexus.snapshot (http://IP-ADDRESS/repository/billing-snapshots/): transfer failed for http://IP-ADDRESS/repository/billing-snapshots/org/billing/billing-service/0.0.1-SNAPSHOT/billing-service-0.0.1-20240305.221751-1.jar: Connection reset by peer -> [Help 1]
Pom文件内容如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.2.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>org.billing</groupId> <artifactId>billing-service</artifactId> <version>0.0.1-SNAPSHOT</version> <name>billing-service</name> <description>billing-service</description> <properties> <java.version>17</java.version> </properties> <distributionManagement> <snapshotRepository> <id>nexus.snapshot</id> <name>nexus-snapshot</name> <url>http://IP-ADDRESS/repository/billing-snapshots/</url> </snapshotRepository> </distributionManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project>
解决方案
以下是针对该问题的排查和解决步骤:
1. 检查Nexus仓库配置与状态
- 确认目标快照仓库
billing-snapshots的存储空间是否充足,磁盘满会直接导致上传中断。 - 核实Maven部署用户对该仓库拥有
Deploy权限,权限不足会被Nexus主动断开连接。 - 查看Nexus本地日志(通常在
sonatype-work/nexus3/log目录),排查是否有仓库配置、存储相关的错误提示。
2. 修复Maven传输进度计算异常
调试日志中的文件大小不匹配错误,是Maven传输组件的已知BUG,可通过以下方式解决:
- 升级Maven到最新稳定版本(如3.9.x),旧版本传输监听器存在进度计算逻辑问题。
- 在本地
settings.xml中配置HTTP客户端参数,优化传输稳定性:
<servers> <server> <id>nexus.snapshot</id> <username>你的Nexus部署用户名</username> <password>你的Nexus部署密码</password> <configuration> <wagonProvider>httpclient</wagonProvider> <httpConfiguration> <all> <usePreemptive>true</usePreemptive> <connectionTimeout>30000</connectionTimeout> <readTimeout>60000</readTimeout> </all> </httpConfiguration> </configuration> </server> </servers>
3. 排查网络连接问题
Connection reset by peer多为网络层面问题,需做以下检查:
- 测试本地机器与Nexus服务器的网络连通性,执行
ping IP-ADDRESS和telnet IP-ADDRESS 8081确认无丢包或端口不通情况。 - 若Nexus部署在云服务器,检查云平台防火墙规则,确保允许本地IP访问Nexus的仓库端口。
- 暂时关闭本地杀毒软件、防火墙,避免其拦截Maven的上传请求。
4. 验证Jar文件完整性
- 检查本地
target目录下的Jar文件是否损坏,执行jar tf billing-service-0.0.1-SNAPSHOT.jar,若能正常列出文件内容则说明文件完好。 - 重新执行
mvn clean package生成全新Jar文件,再尝试mvn deploy,排除旧文件损坏的影响。
5. 调整Maven Deploy插件配置
- 显式指定最新版本的Maven Deploy插件,避免版本兼容问题:
在Pom的<build><plugins>节点中添加:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>3.1.2</version> <configuration> <skip>false</skip> </configuration> </plugin>
- 确保
settings.xml中已配置对应nexus.snapshot的认证信息(用户名、密码),否则会因身份验证失败导致上传中断。
内容的提问来源于stack exchange,提问作者Noureddine
相关产品推荐
相关产品推荐

