Copy all dependencies *and* generated artifacts to directory

Hello All,

I’m using the Java plugin to build an app and I’d like to copy all dependencies and the resultant Jar files to a “lib/” directory for use by some wrapper scripts. I have the following

task install(type: Copy) {
  dependsOn build
  from configurations.runtime
  into "${project.projectDir}/script/lib"
}

however this copies all dependencies except for the app itself. How can I copy the app itself as well? I read that the Java plugin has an “archives” configuration that might have the produced artifact but adding from configurations.archives does not result in the app artifact being present in the target directory.

Hi @FredClausen

You can do the following

task install(type: Copy) {
dependsOn build
from configurations.runtime
from jar
into “${project.projectDir}/script/lib”
}

Indeed, the from method of the Copy task evaluates its argument as per Project.files(), and Project.files() can task a task as input. It resolves the call to the output of the task.
You can of course create another Jar task, if the default jar task does not suit your need.

1 Like

Thanks! That did the trick.