Search code examples
mavenmysql-connector

maven Error creating shaded jar: error in opening zip file


I am trying to build my dropwizard project using the following command :

mvn package

I am getting the following error :

Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.3:shade (default) on project rest-api: Error creating shaded jar: error in opening zip file /Users/ldelaney/.m2/repository/mysql/mysql-connector-java/5.1.36/mysql-connector-java-5.1.36.jar

I have checked, the jar is there, right where maven is looking.

I have also tried blowing it away, and running :

mvn clean
mvn package

But the error just will not go away. My IDE is not showing me any errors.

Also, here is my dependency in the POM :

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.36</version>
</dependency>

Here is the entire POM file.

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.company.test</groupId>
<artifactId>rest-api</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <dropwizard.version>1.0.5</dropwizard.version>
    <mongodriver.version>3.4.2</mongodriver.version>
    <mysqlConnector.version>5.1.36</mysqlConnector.version>
    <log4j.version>1.2.17</log4j.version>
</properties>

<dependencies>

    <!-- Drop Wizard -->
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-core</artifactId>
        <version>${dropwizard.version}</version>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-auth</artifactId>
        <version>${dropwizard.version}</version>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-db</artifactId>
        <version>${dropwizard.version}</version>
    </dependency>
    <dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-hibernate</artifactId>
        <version>${dropwizard.version}</version>
    </dependency>

    <!-- MYSQL and Hibernate -->

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysqlConnector.version}</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.193</version>
    </dependency>

    <!-- Log4j dependencies -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j.version}</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <createDependencyReducedPom>true</createDependencyReducedPom>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <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.ServicesResourceTransformer"/>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>application.ServerApplication</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Anyone have any ideas?


Solution

  • From the OP response, it looks like in .m2/repository/mysql-connector-java/5.1.36 there is only pom.xml file. Please do the following,

    1. if you are using either nexus or artifactory repositories in your organization. delete mysql-connector coordinates and corresponding pom.xml file.
    2. Ensure that your firewall is configured such that you can download file from here. Central repository is by default configured with maven installation.
    3. Upgrade to maven 3 if you are on maven 2.

    I just copied your pom and i was able to successfully build. I have no artifactory or nexus as well. Could you try following,

    1. Go to your maven installation and specify a different repository location. You should go to /conf/settings.xml and uncomment and change <localRepository>/path/to/local/repo</localRepository> to a path. Make sure you do chmod +777 to that path.
    2. If the problem persists, then manually download mysql-connector-java-5.1.36.jar and place it there. See if it works.
    3. if 2 does not work, then try step 2 again but run mvn with -o flag. This is offline flag and maven will not download dependency.

    If it does not work, can you show your maven output with -X flag,

    mvn -U -X -e install