我想要一个胖子 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类。如何从胖 jar 中排除提供的依赖项?编辑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)
}
最佳答案
看一看有关排除影子 jar 依赖项的this article。
不久,根据本文的介绍,仅通过shadowJar
的依赖项排除某些依赖项不足以排除其传递性依赖项,就像您已经提到的那样。解决方案是修改运行时配置,以排除某些依赖项,例如:
configurations {
runtime.exclude %what you need to exclude%
}
希望对您有所帮助。