Maven执行mvn verify报错:无法处理依赖,zip文件为空
Maven verify执行时BanDuplicateClasses报错:zip file is empty的解决方法
问题重现
执行mvn verify时出现如下报错:
[INFO]
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (no-duplicate-classes) @ commons ---
[INFO] Adding ignore: module-info
[INFO] Adding ignore: META-INF/versions/*/module-info
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BanDuplicateClasses failed with message:
Rule 0: org.apache.maven.plugins.enforcer.BanDuplicateClasses failed with message:Unable to process dependency org.springframework:spring-beans:jar:5.2.25.RELEASE:compile due to zip file is empty
对应的Maven enforcer插件配置:
<projects> <!-- ... dependencies omitted but included spring boot 2.7 ... --> <build> <plugins> <!-- ... other plugins ... --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <executions> <execution> <id>no-duplicate-classes</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <banDuplicateClasses> <findAllDuplicates>true</findAllDuplicates> <ignoreWhenIdentical>true</ignoreWhenIdentical> </banDuplicateClasses> </rules> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
环境:MacOS、Java 11、Maven 3.8.4
报错原因
本地Maven仓库中org.springframework:spring-beans:jar:5.2.25.RELEASE依赖包损坏或下载不完整,导致enforcer插件解析该jar时识别为空压缩文件,无法完成重复类检查。
修复步骤
- 删除损坏的依赖目录:找到本地Maven仓库中该依赖的路径(默认路径为
~/.m2/repository/org/springframework/spring-beans/5.2.25.RELEASE),删除整个5.2.25.RELEASE文件夹。 - 强制重新下载依赖:执行命令
mvn clean install -U,-U参数会强制Maven更新依赖,重新下载完整的spring-beans包。 - 验证修复结果:再次运行
mvn verify,确认报错消失。
额外排查(如果上述步骤无效)
- 检查Maven的镜像配置(
settings.xml)是否正常,确保能访问到可靠的镜像源。 - 手动下载
spring-beans-5.2.25.RELEASE.jar,放到对应仓库路径下替换损坏文件。
内容的提问来源于stack exchange,提问作者3ygun
相关产品推荐
相关产品推荐

