我正在使用gradle创建一个fat jar,build.gradle如下:
...
dependencies {
compile files('local_path1')
compile files('local_path2')
runtime files('local_path3')
}
task customFatJar(type: Jar) {
manifest {
attributes 'Main-Class': 'MyMainClass'
}
archiveName = 'my-jar'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
现在,一旦我运行“customFatJar”任务,生成的 jar 就包含路径“local_path1”和“local_path2”中的依赖 jar。但生成的jar在路径“local_path3”中不包含依赖jar。
请让我知道实现此目的的正确依赖配置。
最佳答案
当您将 local_path3
定义为 runtime
时,您也需要将它们添加到脚本中。目前它只是收集所有运行时
库。它可能看起来像:
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
关于java - 如何在从 gradle jar 任务生成的 jar 中包含运行时依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54547329/