Could not determine dependencies of task, while dynamically creating tasks


(nm2501) #1

Hi, I’m trying to dynamically create some tasks which package up various different artifacts. I’m also adding each of those tasks to the ‘compile’ artifact configuration. However I get the error message “Could not determine the dependencies of task ‘:uploadArtifacts’.”

If I remove the dynamic generation of tasks and type out the definition of the tasks long-hand then it works fine. Although I’d prefer not to do this because I may have many more different zips than just Debug and Release.

I was wondering if anyone could please help me with this.

The code:

configurations {
    compile
}
["Debug", "Release"].each { conf ->
    task("package" + conf, type: Zip) {
        classifier = conf
        includes = ["src/*.h", "lib/$conf/*.lib"]
        baseName = 'external-lib'
        includeEmptyDirs = false
        from "."
    }
    configurations.compile.artifacts.add "package" + conf
}
task uploadArtifacts(type: Upload) {
    group = "Packaging"
    description = "Uploads all packages to the repository."
    uploadDescriptor = true
    descriptorDestination = new File("ivy.xml")
    configuration = configurations.compile
}

The command line: gradle tasks

The error: Execution failed for task ‘:tasks’. > Could not determine the dependencies of task ‘:uploadArtifacts’.


(Peter Niederwieser) #2

I’d be surprised if ‘configurations.compile.artifacts.add(someString)’ worked. Usually you’d do something like ‘artifacts { compile tasks[“package$conf”] }’. Instead of looking up the task with ‘tasks[“package$conf”]’, you could also store it in a variable upon creation (the ‘task’ method returns a ‘Task’ object).


(nm2501) #3

Thanks Peter. You were right. I have corrected a subset of the above code to:

["Debug", "Release"].each { conf ->
    artifacts {
        compile task("package" + conf, type: Zip) {
            classifier = conf
            includes = ["src/*.h", "lib/$conf/*.lib"]
            baseName = 'external-lib'
            includeEmptyDirs = false
            from "."
        }
    }
}

(Peter Niederwieser) #4

Creating the task inside the ‘artifacts’ block is very unusual. I guess it will work, but I don’t recommend it.