Adding a dependsOn to an existing task


(mark.harris) #1

Hello,

How do I add a dependsOn dependency to a task contained in the Java plugin, such as compileTestJava or compileJava?

Thanks.


(René Groeschke) #2

Hello,

Gradle provides two ways to configure given tasks and it doesn’t matter where those tasks come from. you can use this notation:

compileJava.dependsOn anotherTask

or if you can use this syntax:

compileJava{
    dependsOn anotherTask
}

The userguide has more details about that at http://gradle.org/docs/current/userguide/userguide_single.html#configureUsingVar

regards, René


(mark.harris) #3

Thank you.


(Zbyszek Sokolowski) #4

but

sonar.dependsOn test

gives:

Executing command: “tasks”

FAILURE: Build failed with an exception.

  • Where: Script ‘E:\workspaces_old\SaaS2\orchestration\sonar.gradle’ line: 4

  • What went wrong: A problem occurred evaluating script. > Could not find method dependsOn() for arguments [task ‘:test’] on root project ‘orchestration’.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED


(René Groeschke) #5

If you’re using the sonar plugin shipped with gradle, “sonar” is an extension to the project and not a task. The sonar task is “sonarAnalyze” so

sonarAnalyze.dependsOn test

is the way to go for you.


(Zbyszek Sokolowski) #6

ok thank you, my mistake is I use a command gradle sonar but it actually runs sonarAnalyze task