# Adding a dependsOn to an existing task

**URL:** <https://discuss.gradle.org/t/adding-a-dependson-to-an-existing-task/6463>\
**Category:** Old Forum Archive\
**Created:** [May 17, 2012, 2:35am UTC](https://discuss.gradle.org/t/adding-a-dependson-to-an-existing-task/6463 "2012-05-17T02:35:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CouldBeAnother](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@CouldBeAnother](https://discuss.gradle.org/u/CouldBeAnother)\
**Post date:** [May 17, 2012, 2:35am UTC](https://discuss.gradle.org/t/adding-a-dependson-to-an-existing-task/6463/1 "2012-05-17T02:35:00Z")

</div>

Hello,

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

Thanks.

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [May 17, 2012, 6:12am UTC](https://discuss.gradle.org/t/adding-a-dependson-to-an-existing-task/6463/2 "2012-05-17T06:12:00Z")

</div>

Hello,

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

```gradle
compileJava.dependsOn anotherTask

```

or if you can use this syntax:

```gradle
compileJava{
    dependsOn anotherTask
}

```

The userguide has more details about that at [http://gradle.org/docs/current/userguide/userguide\_single.html#configureUsingVar](http://gradle.org/docs/current/userguide/userguide_single.html#configureUsingVar)

regards, René

---

<div class="post-metadata">

**Author:** ![CouldBeAnother](https://avatars.discourse-cdn.com/v4/letter/c/b5a626/32.png) [@CouldBeAnother](https://discuss.gradle.org/u/CouldBeAnother)\
**Post date:** [May 17, 2012, 8:26pm UTC](https://discuss.gradle.org/t/adding-a-dependson-to-an-existing-task/6463/3 "2012-05-17T20:26:00Z")

</div>

Thank you.

---

<div class="post-metadata">

**Author:** ![Zbyszek\_Sokolowski](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/zbyszek_sokolowski/32/384_2.png) [@Zbyszek\_Sokolowski](https://discuss.gradle.org/u/Zbyszek_Sokolowski)\
**Post date:** [November 19, 2012, 3:31pm UTC](https://discuss.gradle.org/t/adding-a-dependson-to-an-existing-task/6463/4 "2012-11-19T15:31:00Z")

</div>

but

```gradle
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

---

<div class="post-metadata">

**Author:** ![Rene](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/rene/32/8082_2.png) [@Rene](https://discuss.gradle.org/u/Rene)\
**Post date:** [November 19, 2012, 3:34pm UTC](https://discuss.gradle.org/t/adding-a-dependson-to-an-existing-task/6463/5 "2012-11-19T15:34:00Z")

</div>

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

```gradle
sonarAnalyze.dependsOn test

```

is the way to go for you.

---

<div class="post-metadata">

**Author:** ![Zbyszek\_Sokolowski](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/zbyszek_sokolowski/32/384_2.png) [@Zbyszek\_Sokolowski](https://discuss.gradle.org/u/Zbyszek_Sokolowski)\
**Post date:** [November 19, 2012, 3:39pm UTC](https://discuss.gradle.org/t/adding-a-dependson-to-an-existing-task/6463/6 "2012-11-19T15:39:00Z")

</div>

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