Why it doesn't download dependency? this is code from custom plugin

(Zbyszek Sokolowski) #1
private void setJSTestDriver(Project project) {
      project.repositories {
      maven { url 'http://local:8081/artifactory/testautomation-ext-local' }
    project.configurations {
    project.dependencies {
      jtestdriver 'net.awired.com.googlecode.jstestdriver:jstestdriver:1.3.5'
         project.tasks.add(name: "$runJSTestDriver", type: JavaExec, group: 'Sonar utils', description: 'Run JSTestDriver') {
      dependsOn project.configurations.jtestdriver
      ext.jsTestDriverResultsDir = "/jstestdriver"
      inputs.source "wwwroot"
      main = 'com.google.jstestdriver.Main'
      classpath {
                project.files("${project.getBuildDir()}" + ext.jsTestDriverResultsDir),
        args =
                  "--config", "jsTestDriver.conf",
                  "--port", "9876",
                  "--browser", "${project.sonarutils.js.browserPath}",
                  "--testOutput", "${project.getBuildDir()}" + ext.jsTestDriverResultsDir,
                  //"--runnerMode", "DEBUG",
    project.tasks.getAt(DevLanguage.JAVASCRIPT.getTaskName()).dependsOn(project.tasks.getByName(runJSTestDriver ))

I suppose that it should download a JSTestdriver from repo when I trigger a task but something escapes me. Could you help me?

(Peter Niederwieser) #2

The ‘args =’ shouldn’t be inside the closure passed to ‘classpath’.

(Evgeny Goldin) #3



{ mavenCentral() }

configurations { jtestdriver }


{ jtestdriver ‘junit:junit:4.11’ }

task runJSTestDriver( dependsOn: configurations.jtestdriver ) << {



Have to uncomment “configurations.jtestdriver.files” to make it download the dependency. Is depending on configuration really works? Javadoc mentions “other tasks”.

(Tye Howard) #4

You can force the resolve using something like this:

private void setJSTestDriver(Project project) {
    project.repositories { mavenCentral() }
    project.configurations { jtestdriver }
    project.dependencies {
    jtestdriver 'junit:junit:3.8.1'
    project.tasks.add(name: "runJSTestDriver", description: 'Run JSTestDriver') {
    project.tasks["runJSTestDriver"].doFirst {

(Peter Niederwieser) #5

It works, but not in the way you expect it to. Depending on a ‘Buildable’ (like a ‘Configuration’) adds a task dependency on all tasks tracked by the ‘Buildable’. In your case, since the configuration only contains external dependencies, this amounts to zero tasks.

Why do you need to enforce the resolve? As soon as the configuration gets queried for its files (in one way or another), it will get resolved anyway. And if it never gets queried, why would it need to get resolved?

(Evgeny Goldin) #6

Thanks! I was trying to reproduce the original question scenario (if I understood it correctly) - force dependencies download when the task starts.

(Zbyszek Sokolowski) #7

thank you, it was done because of hurry, I didn’t noticed a braces in incorrect place.

(Zbyszek Sokolowski) #8

one more question Peter from above snippet of code how to set lazily from extensions, this below doesn’t work

"--browser", "${project.sonarutils.js.browserPath}",

(Zbyszek Sokolowski) #9

I figured out something like this and this works:

"--browser", "${->project.sonarutils.js.browserPath}",