11

I am getting this error during my Maven build.

Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.4.3:shade (default) on project dl4j-examples: Error creating shaded jar: invalid LOC header (bad signature) -> [Help 1] [ERROR]

This is my pom.xml file.

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>${maven-shade-plugin.version}</version>
            <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <shadedClassifierName>${shadedClassifier}</shadedClassifierName>
                <createDependencyReducedPom>true</createDependencyReducedPom>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>org/datanucleus/**</exclude>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.DSA</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                        </excludes>
                    </filter>
                </filters>

            </configuration>

            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>reference.conf</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

I have tried to delete the jar file multiple times that does not seem to work.

Ayman Patel
  • 564
  • 2
  • 8
  • 23
  • 1
    Have you tried deleting (after a previous backup...) your `.m2\repository` folder? – Ben Jun 04 '18 at 07:39
  • 2
    The jar returned from repo is corrupted. Try downloading it from a different mirror. That's why even cleaning your local repo won't fix it. – cisk Jun 04 '18 at 09:42

3 Answers3

17

I also faced same issue, Ben is correct, it's the case of corrupt jar file. Just go to .m2 repo folder and delete it from there and again build it (mvn clean install). It would resolve the issue.

5

I've been facing this issue for a long time

So I decided to automate the identification and the removal of corrupt jars

this is the util class I created for this purpose:

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.jar.JarFile;

public class MavenFix {

    public static void main(String[] args) throws IOException {
        Files.walk(Paths.get("C:/data/.m2/repository"))
        .filter(file -> file.toString().endsWith("jar"))
        .forEach(path -> {
            try {
                System.out.print(".");
                new JarFile(path.toString(), true).getManifest();
            } catch (Exception e) {
                System.out.println();
                System.out.println(path + " - " + e.getMessage());
                try {
                    cleanAndDeleteDirectory(path.getParent().toFile());
                } catch (IOException e1) {
                    System.err.println(e1.getMessage());
                }
            }
        });
    }

    public static void cleanAndDeleteDirectory(File dir) throws IOException {
        File[] files = dir.listFiles();
        if (files != null && files.length > 0) {
            for (File aFile : files) {
                Files.delete(aFile.toPath());
            }
        }
        Files.delete(dir.toPath());
    }
}
  • You may want to check out, https://maven.apache.org/plugins/maven-dependency-plugin/examples/purging-local-repository.html – Darren Forsythe Jan 28 '20 at 15:51
  • 1
    Thanks for the tip @Darren, but I work with a VPN with limited bandwidth and it takes hours to download all dependencies, so this solution works better for me – Tiago Mazzucco Jan 30 '20 at 16:46
2

i face same problem just delete it from .m2 folder and again build ur issue will be resolved