[英]How to include runtime dependency in jar generated from gradle jar task
我正在使用gradle创建一个胖子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
,您也需要将它们添加到脚本中。 目前,它仅收集所有runtime
库。 它可能看起来像:
from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
您应该查看有关Java插件创建的配置的文档以及它们之间的关系。
为了不遗漏胖子中的单个运行时依赖项,您应该依赖runtimeClasspath
配置:
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.