1

Already referred following SO question: Deploying Maven project throws java.util.zip.ZipException: invalid LOC header (bad signature)

but my question is I face this error:

Error creating shaded jar: invalid LOC header (bad signature)

whenever a new artifact is added to pom.xml.

If I delete the .m2 folder and rerun clean build, then everything works fine. My question is : is deleting the .m2 folder the only solution? Isn't there a cleaner solution available?

Is this an issue with the shaded plugin (because irrespective of the which new artifact is getting added, the shade plugin fails with this error and resolves after deleting .m2). I also have multiple repos define, could it be an issue?

Repo configuration: (local repo is to install local jars to maven)

<repositories>
    <repository>
        <id>local-maven-repo</id>
        <url>file:///${local.repo.path}</url>
        <releases>            
            <updatePolicy>always</updatePolicy>            
          </releases>
    </repository>
    <repository>
        <id>central</id>
        <url>http://repo.maven.apache.org/maven2/</url>
    </repository>
    <repository>
        <id>ga-all-repository</id>
        <url>https://maven.repository.redhat.com/ga/</url>      
    </repository>
  </repositories>

Maven shade configuration

<plugin>                                
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.1.0</version>
    <execution>                 
        <id>add-thirdParty</id>                     
        <phase>package</phase>
        <goals>
            <goal>shade</goal>
        </goals>
        <configuration>                         
            <outputFile>${project.basedir}/target/tp.jar</outputFile>                                               
            <source>1.7</source>
            <target>1.7</target>
            <filters>                               
                <filter>
                    <artifact>*:*</artifact>
                    <excludes>
                        <exclude>META-INF/*.SF</exclude>
                        <exclude>META-INF/*.DSA</exclude>
                        <exclude>META-INF/*.RSA</exclude>
                    </excludes>
                </filter>
            </filters>          
        </configuration>                                                                        
    </execution>
</plugin>
tryingToLearn
  • 10,691
  • 12
  • 80
  • 114
  • Have you tried to delete the .m2/**/*.repositories files instead of deleting the full .m2 directory? – Little Santi Aug 02 '18 at 12:34
  • No I have not . – tryingToLearn Aug 02 '18 at 12:36
  • Delete the local cache as suggested and afterwards [configure the checksum policy](https://maven.apache.org/settings.html#Repositories) to fail the build if wrong checksums calculated. After having done this rebuild your project...Apart from that remove the configuration `ile:///${local.repo.path}` .... – khmarbaise Oct 13 '18 at 14:28

1 Answers1

1

I had the same issue:

Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.0.0:shade (default) on project: Error creating shaded jar: invalid LOC header (bad signature)

In my case, I had jar with the same version and name of one dependency that was included to another dependency. And I checked it using lifecycle commands of maven: enter image description here

So, I deleted this jsoup-1.11.3.jar and regenereted it via another library (after adding in POM) that contains it also. The issue was gone.

Yes, deleting of maven directory is also as solution, but I'd prefer to check properly cause of the problem before doing it.

Community
  • 1
  • 1
invzbl3
  • 5,872
  • 9
  • 36
  • 76