Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用';时获取Gradle中的运行库列表;java库&x27;和';api&x27;而不是';编译';_Java_Gradle - Fatal编程技术网

使用';时获取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
}