Given java import, find where it comes from

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?

|    +--- 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

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.

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.

  • “build --scan

Just run with --scan

  • “make the root project dependencies task depend on the other projects dependencies tasks”
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.

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

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.