Search code examples
gobazel-gazelle

How to use `bazel cquery` to find out who brings an external dependency?


My bazel build fails with the following error

link: package conflict error: github.com/golang/protobuf/ptypes/timestamp: multiple copies of package passed to linker:
    @io_bazel_rules_go//proto/wkt:timestamp_go_proto
    @com_github_golang_protobuf//ptypes/timestamp:timestamp
Set "importmap" to different paths or use 'bazel cquery' to ensure only one
package with this path is linked.

In the error message, I see use 'bazel cquery' to ensure only one package, how can I find out who brings/uses @com_github_golang_protobuf//ptypes/timestamp:timestamp using bazel cquery?


Solution

  • Found the query

    bazel cquery "somepath(//..., @com_github_golang_protobuf//ptypes/timestamp:timestamp)"