Windows Gradle构建:无法扩展ZIP

dldeef67  于 2023-04-21  发布在  Windows
关注(0)|答案(1)|浏览(224)

我正在开发一个MapReduce应用程序,目前正在使用Gradle构建项目。我使用以下依赖项,当我执行./gradlew clean build时,我得到了无法扩展ZIP错误。

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)

我试着清除了gradle缓存gradlew cleanBuildCache --refresh-dependencies,但没有成功。

pinkon5k

pinkon5k1#

我能够弄清楚这个问题。我的目标是创建一个fatjar,为此,我更新了gradle jar任务来创建一个fatjar。

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

问题是,在C:\Users\..\.gradle\cache\..文件夹中有一些依赖项没有.jar文件.在我的情况下只有.pom文件.所以我删除了任务并创建了一个新任务(customFatJar)只获取.jar文件.这解决了这个问题.
修复:

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

相关问题