Copy task in a custom plugin is up-to-date but I have no idea why

I have written a Gradle plugin. The plugin createsa task that should copy dependencies into a folder. But the task is always up-to-date, and I have no idea what I make wrong:

My plugin/build script:

import org.gradle.api.*
import org.gradle.api.artifacts.*
import org.gradle.api.tasks.*
  apply plugin: SamplePlugin
  repositories { mavenCentral() }
dependencies { sample 'commons-lang:commons-lang:2.6' }
  class SamplePlugin implements Plugin<Project> {
    void apply(Project project) {
  Configuration sample = project.configurations.add("sample")
  project.task(type: Copy, "test") << {
   from files(sample)
   into "$buildDir/xxx"


:test UP-TO-DATE
  Total time: 0.39 secs

Expected behaviour: Copy commos-lang-2.6.jar to the directory build/xxx

It’s this line:

project.task(type: Copy, “test”) << {

It should be:

project.task(type: Copy, “test”) {

This is a classic execution-time-instead-of-configuration-time error. Basically, you are trying to configure the copy task after it has been executed.

We have plans to help protect this kind of error by warning if you try and change the configuration of a task after you have started executing it, but it’s a large and tricky change so will take a while.


thanks for your answer. I changed my Gradle script as you suggested. But

then I get an exception. See (Running gradle with option -i)


from files(sample)


from project.files(sample)