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


(H W) #1

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"
  }
 }
}

Output:

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

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


(Luke Daley) #2

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.


(H W) #3

Hello,

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

then I get an exception. See https://gist.github.com/anonymous/d5dd7824fcf2e0888c1a (Running gradle with option -i)


(Luke Daley) #4

Change:

from files(sample)

To:

from project.files(sample)