如何确保Gradle获取所有声明的和传递的依赖项并将它们添加到输出jar?我正在尝试使用概述here的配方,但似乎实际上并不包含传递依赖。
我希望包含这些依赖项,以便ProGuard可以正确地优化和缩小输出。
这是一个示例build.gradle
,表明没有提取传递依赖:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile('com.itextpdf:itextpdf:5.4.3') { transitive = true }
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:4.10'
}
}
jar {
dependsOn configurations.runtime
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
task proguard(type: proguard.gradle.ProGuardTask, dependsOn: build) {
configurations.runtime.each {
println it
}
injars jar.archivePath
outjars 'output.jar'
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
keep "public class part1.** { * ; }"
//dontnote
//dontwarn
dontobfuscate
}
对于此示例项目,我正在使用http://itextpdf.com/examples/iia.php?id=12中的代码示例。 POM at MavenCentral表示BouncyCastle库是编译依赖项,但上面的build.gradle
不将它们打包到输出JAR中,甚至将它们拉入~/.gradle
工件缓存中。
结果是,当我在启用警告的情况下运行gradle proguard
时,由于org.bouncycastle.*
类未被解析,构建失败。例如:
Warning: com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.bouncycastle.tsp.TimeStampTokenInfo
如果无法使用ProGuard解决此问题(禁用警告在此处工作,但在我的大型项目中没有,同样由于类似的错误消息),是否有另一种方法让Gradle收缩完整运行时脂肪罐?
答案 0 :(得分:1)
查看itextpdf
的POM,其所有依赖项都是测试依赖项或可选项。因此,除非您声明进一步的依赖关系,否则只有itextpdf
本身将包含在您的胖罐中。