5
我想擁有一個胖罐子但沒有提供的依賴關係。所以我用下面的兩個插件:Gradle影子插件包也提供了所有「提供」的依賴關係,這不應該是這種情況
- https://github.com/johnrengelman/shadow
- https://github.com/nebula-plugins/gradle-extra-configurations-plugin
,並有一個的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
我仍然有所有rangeCache類都放在我的fat jar中。我如何從我的胖罐子中排除提供的依賴關係?
編輯1: 這似乎也不起作用,臨時依賴關係仍然被複制到fat 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)
}
這個不適用於項目。不過,我在鏈接的博客文章中找到了解決方案3,該文章運行良好 – KIC