获取运行时库列表摇篮,而使用的Java库“和“API”而不是“编译”

问题描述 投票:1回答:1

我用这个代码来获得所需要的库和编译过程中复制它们:

task copyToLib( type: Copy ) {
    into "$buildDir/libs/lib"
    from configurations.runtime
}

jar {
    dependsOn copyToLib
    ...
}

这是确定的,当我使用旧的摇篮模型添加使用qazxsw POI依赖关系:

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' ... } 将是空的。任何替代方案?

java gradle
1个回答
2
投票

configurations.runtime配置也被弃用,就像runtime配置(见文档在这里:compile

所以,你需要改变你的https://docs.gradle.org/4.10/userguide/java_plugin.html#tab:configurations子句中from任务,拿起一个正确的配置:我觉得你的情况,你应该使用copyToLib(编辑使用compileClasspath代替,见下面的评论):

runtimeClasspath

看到这个配置的依赖关系图,可以帮助你拿起正确的配置: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 }

© www.soinside.com 2019 - 2024. All rights reserved.