使用';时获取Gradle中的运行库列表;java库&x27;和';api&x27;而不是';编译';
我使用此代码获取所需的库,并在编译期间复制它们:使用';时获取Gradle中的运行库列表;java库&x27;和';api&x27;而不是';编译';,java,gradle,Java,Gradle,我使用此代码获取所需的库,并在编译期间复制它们: task copyToLib( type: Copy ) { into "$buildDir/libs/lib" from configurations.runtime } jar { dependsOn copyToLib ... } 当我使用lagecy-Gradle模型使用compile添加依赖项时,这是正常的: dependencies { compile 'net.objecthunter:e
task copyToLib( type: Copy ) {
into "$buildDir/libs/lib"
from configurations.runtime
}
jar {
dependsOn copyToLib
...
}
当我使用lagecy-Gradle模型使用compile
添加依赖项时,这是正常的:
dependencies {
compile 'net.objecthunter:exp4j:0.4.8'
compile 'io.undertow:undertow-core:2.0.16.Final'
compile 'org.postgresql:postgresql:42.2.5'
...
}
但是当我使用api
关键字时:
dependencies {
api 'net.objecthunter:exp4j:0.4.8'
api 'io.undertow:undertow-core:2.0.16.Final'
api 'org.postgresql:postgresql:42.2.5'
...
}
configurations.runtime
将为空。是否有其他选择?运行时配置也已被弃用,如编译
配置(请参阅此处的文档:)
因此,您需要更改copyToLib
任务中的from
子句,以获得正确的配置:我认为在您的情况下,您应该使用compileClasspath
(EDIT使用runtimeClasspath
,请参见下面的注释):
请参阅此可帮助您选择正确配置的配置依赖关系图:注意,这不包括添加到
runtimeOnly
的依赖关系,实际上是复制编译类路径。如果你想要所有的运行库,你应该使用runtimeClasspath
@LouisJacomet你是对的,谢谢。我已经更新了我的答案。
dependencies {
api 'net.objecthunter:exp4j:0.4.8'
api 'org.postgresql:postgresql:42.2.5'
api 'io.undertow:undertow-core:2.0.16.Final'
}
task copyToLib(type: Copy) {
into "$buildDir/libs/lib"
from configurations.runtimeClasspath
}