Adding a dependsOn to an existing task


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



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:

    dependsOn anotherTask

The userguide has more details about that at

regards, René

Thank you.


sonar.dependsOn test


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.


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.

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