[英]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.