javagradleapache-curator

Windows Gradle build : Could not expand ZIP


I'm working on a MapReduce app and currently using Gradle to build the project. I'm using following dependencies and when I execute the ./gradlew clean build I'm getting Could not expand ZIP error.

implementation 'org.apache.hive:hive-jdbc:3.1.3'
implementation 'org.apache.hadoop:hadoop-common:3.3.2'
implementation 'org.apache.hadoop:hadoop-hdfs:3.3.2'

Stacktrace

 Could not expand ZIP 'C:\Users\..\.gradle\caches\modules-2\files-2.1\org.apache.curator\apache-curator\2.12.0\b1ff6ce0741facb15217ae9254ee7167bc7b15e\apache-curator-2.12.0.pom'.


org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':jar'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:188)
        at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:186)

I tried clearing out gradle cache gradlew cleanBuildCache --refresh-dependencies that didn't workout.


Solution

  • I was able to figure out the issue. My goal was to create a fatjar and for that I have updated the gradle jar task to create a fat jar.

    jar {
        manifest {
            attributes "Main-Class": "main.Main"
        }
        from {
            configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
        }
        duplicatesStrategy = DuplicatesStrategy.INCLUDE
    }
    

    The issue was, in the C:\Users\..\.gradle\cache\.. folder there were some dependencies without a .jar file. In my case only a .pom file. So I removed the task and created a new task(customFatJar) only to get .jar files. That fixed the issue.

    Fix:

    task customFatJar(type: Jar) {
        manifest {
            attributes 'Main-Class': 'main.Main'
        }
        duplicatesStrategy = DuplicatesStrategy.EXCLUDE
        from {
            configurations.runtimeClasspath.filter {
                it.name.endsWith('.jar')
            }
        }
        with jar
    }