Freewind
Freewind

Reputation: 198398

How to write a task which depends on the built-in `dependencies` task?

Gradle has a dependencies task which can output the dependencies as tree.

I want to write a gradle task which depends on it. I tried:

task hello(dependsOn: 'dependencies') << {
    println("Hello")
}

task hello() << {
    tasks.dependencies.execute()
    println("Hello")
}

But neither works, it will report the dependencies is not found.

And when I use tasks.each({println it}), the output doesn't have dependencies task, but gradle tasks --all have that.

What is the correct way to depend on dependencies?

Upvotes: 1

Views: 398

Answers (1)

Opal
Opal

Reputation: 84884

Still don't get it, the following script works perfectly fine:

apply plugin: 'java'

task hello(dependsOn: 'dependencies') << {
    println("Hello")
}

task hello2() << {
    tasks.dependencies.execute()
    println("Hello")
}

Dependency tree is printed to console.

Upvotes: 2

Related Questions