When trying to run a mvn verify
I’m encountering the following:
[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
My Maven configuration for BanDuplicateClasses
is as follows:
<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>
Computer is MacOS with project in Java 11 and Maven 3.8.4
What is it complaining about? And how do I fix it?
1
Turns out the .jar
file in my ~/.m2/repository/
existed but was empty (0
bytes) thus the error message:
… zip file is empty
Note that mvn clean
doesn’t touch this file it seems.
Thus the fix was to “hand delete the file”:
-
Navigate to the directory
cd ~/.m2/repository/org/springframework/spring-beans/5.2.25.RELEASE
-
Verify the file is empty (
0
bytes) withls -alh
(notice the.jar
file is0B
)total 32 drwxr-xr-x 7 me staff 224B Sep 3 16:44 ./ drwxr-xr-x 24 me staff 768B Sep 3 17:07 ../ -rw-r--r-- 1 me staff 218B Sep 3 16:44 _remote.repositories -rw-r--r-- 1 me staff 0B Sep 3 16:44 spring-beans-5.2.25.RELEASE.jar -rw-r--r-- 1 me staff 40B Sep 3 16:44 spring-beans-5.2.25.RELEASE.jar.sha1 -rw-r--r-- 1 me staff 1.6K Sep 3 16:43 spring-beans-5.2.25.RELEASE.pom -rw-r--r-- 1 me staff 40B Sep 3 16:43 spring-beans-5.2.25.RELEASE.pom.sha1
-
Hard remove that file
rm -rf spring-beans-5.2.25.RELEASE.jar
-
Rerun
mvn verify
which should download the file as needed
TL;DR: ... zip file is empty
might require a direct file delete as Maven seems to not be able to correct some non-downloaded files.