Lazily resolve name of directory and then use it in Sync Task: custom plugin


(Zbyszek Sokolowski) #1

If I have this code it doesn’t work it claims:

Skipping task ':copyJSTestDrvCoverage' as it is up-to-date
Skipping task ':copyJSTestDrvCoverage' as it is up-to-date
:copyJSTestDrvCoverage UP-TO-DATE
project.tasks.add(name: copyTaskJSTestDrv, type: Sync, group: 'Sonar utils', description: 'Download JSTestDriver CodeCoverage plugin') {
      ext.copyToDir = "conf"
      log.info ("copyTaskJSTestDrv: ${->project.sonarutils.js.workingDir}/$copyToDir}")
      from project.configurations.jstestcoverage
      into { project.sonarutils.js.workingDir + "/conf" }
      doLast {
        println destinationDir
      }
    }
  }

but when I change it to

private void setJSTestCoverage(Project project) {
    project.configurations {
      jstestcoverage
    }
    project.dependencies {
      jstestcoverage 'net.awired.com.googlecode.jstestdriver:coverage:1.3.5:patch'
    }
    project.tasks.add(name: copyTaskJSTestDrv, type: Sync, group: 'Sonar utils', description: 'Download JSTestDriver CodeCoverage plugin') {
      ext.copyToDir = "conf"
      log.info ("copyTaskJSTestDrv: ${->project.sonarutils.js.workingDir}/$copyToDir}")
      from project.configurations.jstestcoverage
      //into { project.sonarutils.js.workingDir + "/conf" }
      into { "/conf" }
      doLast {
        println destinationDir
      }
    }
  }

it works how to deal with this situation?


(Zbyszek Sokolowski) #2

I’ve noticed that it works without any trouble with Copy Task because it accepts closure:

project.tasks.add(name: copyTaskJSTestDrv, type: Copy, group: 'Sonar utils', description: 'Download JSTestDriver CodeCoverage plugin') {
      from project.configurations.jstestcoverage
      into { project.sonarutils.js.workingDir + "/conf" }
      doLast {
        log.info("Copied JSTestDriver Cove Coverage Libraries to $destinationDir")
      }
    }

But for sure I don’t understand something


(Szczepan Faber) #3

I don’t understand the problem :slight_smile: I bet that the :copyJSTestDrvCoverage is up-to-date for reason. Run with --info to find out more.

Hope that helps!