0

I'm migrating a project to Gradle.

I have some local deps which are imported via compile fileTree(dir: "libs/$it", include: '*.jar')

However compile is deprecated.

But if I change it to implementation

then my task will copy nothing (except the files which are decleared with runtime):

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

changing configurations.runtime to .compile or implementation doesn't help

What's going on?

elect
  • 6,765
  • 10
  • 53
  • 119
  • Somewhat related question: https://stackoverflow.com/questions/4871656/using-gradle-to-build-a-jar-with-dependencies – Piotr Siupa Jul 19 '19 at 10:57

1 Answers1

2

The documentation on the Gradle Java plugin shows that the configuration runtime has been deprecated. It is superseded by the runtimeOnly configuration, which, like the name says, only provides runtime dependencies. There is however another configuration called runtimeClasspath that extends the configurations runtimeOnly, runtime and implementation.

So just replace the configuration in your example:

task copyToLib(type: Copy) {
    from configurations.runtimeClasspath
    into "$buildDir/output/lib"
}
Lukas Körfer
  • 13,515
  • 7
  • 46
  • 62
  • Be careful with `runtimeClasspath`. It is transitive by default and you can end up with a lot more libraries than you've expected. If you have his problem, use `configurations.runtimeClasspath { transitive = false }`. – Piotr Siupa Jul 19 '19 at 10:59
  • You are right, but using `configurations.runtimeClasspath { transitive = false }` inside the task is dangerous, too, as it will fully disable transitivity for the configuration (not only for the task). There may be other tasks or plugins relying on the default behavior. If required, transitivity should be disabled at the start of the build script directly in a `configurations` closure to make it clear for everyone. – Lukas Körfer Jul 19 '19 at 11:03