首页 文章

Gradle shadow插件包也是所有“提供”的依赖项,不应该是这种情况

提问于
浏览
5

我想要一个胖 jar 但没有提供的依赖项 . 所以我使用以下两个插件:

并有一个build.gradle文件,如下所示:

apply plugin: 'nebula.provided-base'
apply plugin: 'com.github.johnrengelman.shadow'

archivesBaseName = 'range-cache-drivers'
group = 'com.engine'
version = '0.302-SNAPSHOT'

buildDir = 'target'

sourceCompatibility = 1.8
targetCompatibility = 1.8


dependencies {
    provided project(':rangeCache')

    // CSV, TSV, Fixe width
    compile deps.univocityParsers
    // MongoDB
    compile deps.mongo
    // Cassandra
    compile deps.cassandradx
    compile deps.cassandraSnappy
    compile deps.cassandraLZ4
}

但是当我运行 gradle shadowJar 时,我的胖 jar 里仍然有所有的rangeCache类 . 如何从胖箱中排除提供的依赖项?

编辑1:这似乎也没有用,瞬态依赖仍然被复制到胖 jar 里 .

shadowJar {
    dependencies {
        exclude(project(':rangeCache'))
    }
}

编辑2:根据斯坦尼斯拉夫的回答,我做了以下工作以使工作正常:

configurations {
    shadow
    compile.extendsFrom provided
    provided.extendsFrom shadow
}

dependencies {
    provided project(':rangeCache')

    // CSV, TSV, Fixe width
    shadow deps.univocityParsers

    // MongoDB
    shadow deps.mongo

    // Cassandra
    shadow deps.cassandradx
    shadow deps.cassandraSnappy
    shadow deps.cassandraLZ4

    testCompile deps.junit
}

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

task fatJar(type: ShadowJar) {
    configurations = [project.configurations.shadow]
    from(project.sourceSets.main.output)
}

1 回答

  • 1

    看看this article关于排除阴影jar依赖关系 .

    不久,根据这篇文章,只是通过 shadowJar 's dependencies is not enough for exluding it' s传递依赖关系排除一些依赖关系,正如您已经提到的那样 . 解决方法如何做,是修改运行时配置,从中排除一些依赖,如:

    configurations {    
        runtime.exclude %what you need to exclude%
    }
    

    希望,它可能会有所帮助 .

相关问题