I use this code to get the required libraries and copy them during compile:
task copyToLib( type: Copy ) {
into "$buildDir/libs/lib"
from configurations.runtime
}
jar {
dependsOn copyToLib
...
}
It's OK when I use the lagecy Gradle model to add dependencies using 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'
...
}
But when I use api
keyword:
dependencies {
api 'net.objecthunter:exp4j:0.4.8'
api 'io.undertow:undertow-core:2.0.16.Final'
api 'org.postgresql:postgresql:42.2.5'
...
}
The configurations.runtime
would be empty. Any alternative?
The runtime
configuration has also been deprecated, like compile
configuration ( see documentation here : https://docs.gradle.org/4.10/userguide/java_plugin.html#tab:configurations )
So you need to change your from
clause in copyToLib
task, to pick up a correct configuration : I think in your case you should use compileClasspath
(EDIT use runtimeClasspath
instead, see comment below):
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
}
See this configuration dependencies graph that can help you pick up the correct configuration : https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph