Gradle:Uber Jar创建失败,并显示“无法扩展ZIP". [英] Gradle: Uber Jar creation fails with "Could not expand ZIP"

查看:79
本文介绍了Gradle:Uber Jar创建失败,并显示“无法扩展ZIP".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Gradle创建一个Fat/Uber jar.不幸的是,我一直遇到以下错误:

I'm trying to create a Fat/Uber jar using Gradle. Unfortunately, I keep running into the following error:

> Task :fatJar FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':fatJar'.
> Could not expand ZIP '/home/me/.gradle/caches/modules-2/files-2.1/org.apache.drill/drill-client/1.13.0/c90c87887c292a3712eccc7cebdc48b0b9d93ec9/drill-client-1.13.0.pom'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.9/userguide/command_line_interface.html#sec:command_line_warnings

我试图删除我的缓存目录,可能是某些东西损坏了,但仍然没有任何乐趣.

I have tried deleting my cache directory thinking maybe something was corrupted, but still no joy.

build.gradle 文件:

apply plugin: 'java'
apply plugin: 'maven'

group = 'com.me.ps'
version = me.version

sourceCompatibility = 1.8
targetCompatibility = 1.8

buildscript {
    repositories {
        jcenter()
    }
}

repositories {
     [...]
}

dependencies {
    // Explicityly added to in hopes of being included in the fat jar
    compile group: 'org.apache.hadoop', name: 'hadoop-common', version: '2.7.0-me-1803'

    // dependencies listed in the pom.xml
    compile group: 'com.me.ojai', name: 'me-ojai-driver', version: '6.0.1-me'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.6.5'
    compile group: 'org.apache.kafka', name: 'connect-json', version: '1.0.1-me-1803-streams-6.0.1'
    compile group: 'org.apache.spark', name: 'spark-core_2.11', version: '2.2.1'
    compile group: 'org.apache.spark', name: 'spark-streaming_2.11', version: '2.2.1-me-1803'
    compile group: 'org.apache.spark', name: 'spark-streaming-kafka-0-10_2.11', version: '2.2.1-me-1803'
    compile group: 'org.apache.kafka', name: 'kafka-clients', version: '1.0.1-me-1803-streams-6.0.1'

    // dependencies not in the pom.xml, but added to make the gradle build work
    compile group: 'xerces', name: 'xercesImpl', version: '2.11.0'
    compile group: 'org.json', name: 'json', version: '20171018'
    compile group: 'com.google.guava', name: 'guava', version: '19.0'

}

task fatJar(type: Jar) {
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
    manifest {
        attributes 'Main-Class': 'org.Lol'
    }
}

我尝试使用shadowJar插件,但这导致胖子中不包含依赖项.关于这个问题,我有一个单独的问题.目前,我正在使用Maven,它可以完美地构建一个胖子罐.

I have tried using the shadowJar plugin, but that has led to dependencies being not included in the fat jar. I have a separate question regarding that issue. Currently, I'm using Maven which builds a fat jar perfectly.

推荐答案

也许在构建JAR时可以忽略 .pom 文件,如下所示:

Perhaps you could ignore the .pom file when building the JAR, like this:

(configurations.compile.findAll { !it.path.endsWith(".pom") }).collect {
    it.isDirectory() ? it : zipTree(it)
}

这篇关于Gradle:Uber Jar创建失败,并显示“无法扩展ZIP".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆