# Given java import, find where it comes from

**URL:** <https://discuss.gradle.org/t/given-java-import-find-where-it-comes-from/45965>\
**Category:** Help/Discuss\
**Created:** [July 5, 2023, 12:04am UTC](https://discuss.gradle.org/t/given-java-import-find-where-it-comes-from/45965 "2023-07-05T00:04:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![engineer-plus-plus](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/engineer-plus-plus/32/10458_2.png) [@engineer-plus-plus](https://discuss.gradle.org/u/engineer-plus-plus)\
**Post date:** [July 5, 2023, 12:04am UTC](https://discuss.gradle.org/t/given-java-import-find-where-it-comes-from/45965/1 "2023-07-05T00:04:24Z")

</div>

I inherited a bunch of code that’s built by gradle. There a bunch of build.gradle files scattered through the directory structure. I want to get rid of dependency to Mockito, for example. But when I execute this command in the root directory of the project `cat build.gradle|grep mockito `, I get nothing. Yet when I run `gradle :svc-bip-api:dependencies |grep mockito`, I get a bunch of stuff as seen below.

**How can I find out where this dependency is declared?**

```gradle
| +--- org.mockito:mockito-core:4.5.1 (c)
| +--- org.mockito:mockito-junit-jupiter:4.5.1 (c)
+--- org.mockito:mockito-core -> 4.5.1
| +--- org.mockito:mockito-core:4.5.1 (*)
| +--- org.mockito:mockito-junit-jupiter:4.5.1
| | \--- org.mockito:mockito-core:4.5.1 (*)
+--- org.mockito:mockito-core (n)
| +--- org.mockito:mockito-core:4.5.1 (c)
| +--- org.mockito:mockito-junit-jupiter:4.5.1 (c)
+--- org.mockito:mockito-core -> 4.5.1
| +--- org.mockito:mockito-core:4.5.1 (*)
| +--- org.mockito:mockito-junit-jupiter:4.5.1

```

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [July 5, 2023, 7:35am UTC](https://discuss.gradle.org/t/given-java-import-find-where-it-comes-from/45965/2 "2023-07-05T07:35:58Z")

</div>

The easiest would be a build `--scan` if possible.

Unlike most other tasks, the `dependencies` task only runs on one project.  
To run it on all projects you either need to make the root project `dependencies` task depend on the other projects `dependencies` tasks, or call them all explicitly (can also be done in one Gradle invocation), or declare another task of the type that task has for all projects as that would behave like the other tasks.

---

<div class="post-metadata">

**Author:** ![engineer-plus-plus](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/engineer-plus-plus/32/10458_2.png) [@engineer-plus-plus](https://discuss.gradle.org/u/engineer-plus-plus)\
**Post date:** [July 5, 2023, 3:50pm UTC](https://discuss.gradle.org/t/given-java-import-find-where-it-comes-from/45965/3 "2023-07-05T15:50:02Z")

</div>

Thanks for the answer. Would you please elaborate on how to do the things you suggest. Specifically how to:

- “build `--scan`”
- “make the root project `dependencies` task depend on the other projects `dependencies` tasks”
- “call them all explicitly in on Gradle invocation”
- “declare another task of the type that task has for all projects as that would behave like the other tasks”

Sorry I’m a bit of a n00b here. I’m sure there are docs that explain this. It would be lovely if you can direct me to the relevant ones.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [July 5, 2023, 9:58pm UTC](https://discuss.gradle.org/t/given-java-import-find-where-it-comes-from/45965/4 "2023-07-05T21:58:27Z")

</div>

> - “build `--scan`”

Just run with `--scan`

> - “make the root project `dependencies` task depend on the other projects `dependencies` tasks”

```kts
tasks.dependencies {
    dependsOn(subprojects.map { it.tasks.dependencies })
}

```

> - “call them all explicitly in on Gradle invocation”

`./gradlew dependencies :sub1:dependencies :sub2:dependencies`

> - “declare another task of the type that task has for all projects as that would behave like the other tasks”

In all projects add, then execute the `allDependencies` task.

```kts
val allDependencies by tasks.registering(DependencyReportTask::class)

```

If it is just for a one-shot investigation and not permanent you can also use the bad-practice

```kts
allprojects {
    val allDependencies by tasks.registering(DependencyReportTask::class)
}

```

Disclaimer: All written from the top of my head without PC access right now, so errors might be present.
