获取 bazel 目标的依赖树
Get dependency tree for a bazel target
我正在尝试将我的 maven
集成测试迁移到 bazel
。在运行时我遇到了一些问题。为了调试,我想将 maven dependency:tree
与 bazel 的依赖树进行比较。以避免任何额外的依赖关系或检测我是否缺少某些依赖关系。
我们如何比较这些依赖关系(maven
vs bazel
)。有什么方法可以获取 bazel 目标的依赖关系树吗?
bazel query 'deps(//my:target)' --nohost_deps --noimplicit_deps
使用这个 Java example,上面的命令打印:
$ bazel query 'deps(//:java-maven)' --nohost_deps --noimplicit_deps
//:java-maven
//:java-maven-lib
@maven//:com_google_guava_guava
@maven//:v1/http/uk.maven.org/maven2/com/google/guava/guava/28.0-jre/guava-28.0-jre.jar
@maven//:v1/http/uk.maven.org/maven2/com/google/guava/guava/28.0-jre/guava-28.0-jre-sources.jar
@maven//:org_codehaus_mojo_animal_sniffer_annotations
@maven//:v1/http/uk.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations/1.17/animal-sniffer-annotations-1.17.jar
@maven//:v1/http/uk.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations/1.17/animal-sniffer-annotations-1.17-sources.jar
@maven//:org_checkerframework_checker_qual
@maven//:v1/http/uk.maven.org/maven2/org/checkerframework/checker-qual/2.8.1/checker-qual-2.8.1.jar
@maven//:v1/http/uk.maven.org/maven2/org/checkerframework/checker-qual/2.8.1/checker-qual-2.8.1-sources.jar
@maven//:com_google_j2objc_j2objc_annotations
@maven//:v1/http/uk.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar
@maven//:v1/http/uk.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3-sources.jar
@maven//:com_google_guava_listenablefuture
@maven//:v1/http/uk.maven.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
@maven//:com_google_guava_failureaccess
@maven//:v1/http/uk.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar
@maven//:v1/http/uk.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1-sources.jar
@maven//:com_google_errorprone_error_prone_annotations
@maven//:v1/http/uk.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.2/error_prone_annotations-2.3.2.jar
@maven//:v1/http/uk.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.2/error_prone_annotations-2.3.2-sources.jar
@maven//:com_google_code_findbugs_jsr305
@maven//:v1/http/uk.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar
@maven//:v1/http/uk.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2-sources.jar
//:src/main/java/com/example/myproject/App.java
你也可以把它变成可视化图表:
bazel query 'deps(//:java-maven)' --nohost_deps --noimplicit_deps --output=graph | dot -Tpng > graph.png
或者,查看 BUILD 文件表示:
$ bazel query 'deps(//:java-maven)' --nohost_deps --noimplicit_deps --output=build
# /Users/jingwen/code/examples/java-maven/BUILD:9:1
java_binary(
name = "java-maven",
runtime_deps = ["//:java-maven-lib"],
main_class = "com.example.myproject.App",
)
# /Users/jingwen/code/examples/java-maven/BUILD:3:1
java_library(
name = "java-maven-lib",
deps = ["@maven//:com_google_guava_guava"],
srcs = ["//:src/main/java/com/example/myproject/App.java"],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:44:1
jvm_import(
name = "com_google_guava_guava",
tags = ["maven_coordinates=com.google.guava:guava:28.0-jre"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/guava/guava/28.0-jre/guava-28.0-jre.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/com/google/guava/guava/28.0-jre/guava-28.0-jre-sources.jar",
deps = ["@maven//:com_google_guava_listenablefuture", "@maven//:com_google_j2objc_j2objc_annotations", "@maven//:com_google_code_findbugs_jsr305", "@maven//:org_checkerframework_checker_qual", "@maven//:org_codehaus_mojo_animal_sniffer_annotations", "@maven//:com_google_guava_failureaccess", "@maven//:com_google_errorprone_error_prone_annotations"],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:111:1
jvm_import(
name = "org_codehaus_mojo_animal_sniffer_annotations",
tags = ["maven_coordinates=org.codehaus.mojo:animal-sniffer-annotations:1.17"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations/1.17/animal-sniffer-annotations-1.17.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations/1.17/animal-sniffer-annotations-1.17-sources.jar",
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:99:1
jvm_import(
name = "org_checkerframework_checker_qual",
tags = ["maven_coordinates=org.checkerframework:checker-qual:2.8.1"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/org/checkerframework/checker-qual/2.8.1/checker-qual-2.8.1.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/org/checkerframework/checker-qual/2.8.1/checker-qual-2.8.1-sources.jar",
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:74:1
jvm_import(
name = "com_google_j2objc_j2objc_annotations",
tags = ["maven_coordinates=com.google.j2objc:j2objc-annotations:1.3"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3-sources.jar",
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:63:1
jvm_import(
name = "com_google_guava_listenablefuture",
tags = ["maven_coordinates=com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar"],
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:32:1
jvm_import(
name = "com_google_guava_failureaccess",
tags = ["maven_coordinates=com.google.guava:failureaccess:1.0.1"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1-sources.jar",
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:20:1
jvm_import(
name = "com_google_errorprone_error_prone_annotations",
tags = ["maven_coordinates=com.google.errorprone:error_prone_annotations:2.3.2"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.2/error_prone_annotations-2.3.2.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.2/error_prone_annotations-2.3.2-sources.jar",
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:8:1
jvm_import(
name = "com_google_code_findbugs_jsr305",
tags = ["maven_coordinates=com.google.code.findbugs:jsr305:3.0.2"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2-sources.jar",
deps = [],
)
要了解更多信息,请查看 Bazel query how-to 页面。
我正在尝试将我的 maven
集成测试迁移到 bazel
。在运行时我遇到了一些问题。为了调试,我想将 maven dependency:tree
与 bazel 的依赖树进行比较。以避免任何额外的依赖关系或检测我是否缺少某些依赖关系。
我们如何比较这些依赖关系(maven
vs bazel
)。有什么方法可以获取 bazel 目标的依赖关系树吗?
bazel query 'deps(//my:target)' --nohost_deps --noimplicit_deps
使用这个 Java example,上面的命令打印:
$ bazel query 'deps(//:java-maven)' --nohost_deps --noimplicit_deps
//:java-maven
//:java-maven-lib
@maven//:com_google_guava_guava
@maven//:v1/http/uk.maven.org/maven2/com/google/guava/guava/28.0-jre/guava-28.0-jre.jar
@maven//:v1/http/uk.maven.org/maven2/com/google/guava/guava/28.0-jre/guava-28.0-jre-sources.jar
@maven//:org_codehaus_mojo_animal_sniffer_annotations
@maven//:v1/http/uk.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations/1.17/animal-sniffer-annotations-1.17.jar
@maven//:v1/http/uk.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations/1.17/animal-sniffer-annotations-1.17-sources.jar
@maven//:org_checkerframework_checker_qual
@maven//:v1/http/uk.maven.org/maven2/org/checkerframework/checker-qual/2.8.1/checker-qual-2.8.1.jar
@maven//:v1/http/uk.maven.org/maven2/org/checkerframework/checker-qual/2.8.1/checker-qual-2.8.1-sources.jar
@maven//:com_google_j2objc_j2objc_annotations
@maven//:v1/http/uk.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar
@maven//:v1/http/uk.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3-sources.jar
@maven//:com_google_guava_listenablefuture
@maven//:v1/http/uk.maven.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
@maven//:com_google_guava_failureaccess
@maven//:v1/http/uk.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar
@maven//:v1/http/uk.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1-sources.jar
@maven//:com_google_errorprone_error_prone_annotations
@maven//:v1/http/uk.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.2/error_prone_annotations-2.3.2.jar
@maven//:v1/http/uk.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.2/error_prone_annotations-2.3.2-sources.jar
@maven//:com_google_code_findbugs_jsr305
@maven//:v1/http/uk.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar
@maven//:v1/http/uk.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2-sources.jar
//:src/main/java/com/example/myproject/App.java
你也可以把它变成可视化图表:
bazel query 'deps(//:java-maven)' --nohost_deps --noimplicit_deps --output=graph | dot -Tpng > graph.png
或者,查看 BUILD 文件表示:
$ bazel query 'deps(//:java-maven)' --nohost_deps --noimplicit_deps --output=build
# /Users/jingwen/code/examples/java-maven/BUILD:9:1
java_binary(
name = "java-maven",
runtime_deps = ["//:java-maven-lib"],
main_class = "com.example.myproject.App",
)
# /Users/jingwen/code/examples/java-maven/BUILD:3:1
java_library(
name = "java-maven-lib",
deps = ["@maven//:com_google_guava_guava"],
srcs = ["//:src/main/java/com/example/myproject/App.java"],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:44:1
jvm_import(
name = "com_google_guava_guava",
tags = ["maven_coordinates=com.google.guava:guava:28.0-jre"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/guava/guava/28.0-jre/guava-28.0-jre.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/com/google/guava/guava/28.0-jre/guava-28.0-jre-sources.jar",
deps = ["@maven//:com_google_guava_listenablefuture", "@maven//:com_google_j2objc_j2objc_annotations", "@maven//:com_google_code_findbugs_jsr305", "@maven//:org_checkerframework_checker_qual", "@maven//:org_codehaus_mojo_animal_sniffer_annotations", "@maven//:com_google_guava_failureaccess", "@maven//:com_google_errorprone_error_prone_annotations"],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:111:1
jvm_import(
name = "org_codehaus_mojo_animal_sniffer_annotations",
tags = ["maven_coordinates=org.codehaus.mojo:animal-sniffer-annotations:1.17"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations/1.17/animal-sniffer-annotations-1.17.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations/1.17/animal-sniffer-annotations-1.17-sources.jar",
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:99:1
jvm_import(
name = "org_checkerframework_checker_qual",
tags = ["maven_coordinates=org.checkerframework:checker-qual:2.8.1"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/org/checkerframework/checker-qual/2.8.1/checker-qual-2.8.1.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/org/checkerframework/checker-qual/2.8.1/checker-qual-2.8.1-sources.jar",
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:74:1
jvm_import(
name = "com_google_j2objc_j2objc_annotations",
tags = ["maven_coordinates=com.google.j2objc:j2objc-annotations:1.3"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3-sources.jar",
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:63:1
jvm_import(
name = "com_google_guava_listenablefuture",
tags = ["maven_coordinates=com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar"],
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:32:1
jvm_import(
name = "com_google_guava_failureaccess",
tags = ["maven_coordinates=com.google.guava:failureaccess:1.0.1"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1-sources.jar",
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:20:1
jvm_import(
name = "com_google_errorprone_error_prone_annotations",
tags = ["maven_coordinates=com.google.errorprone:error_prone_annotations:2.3.2"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.2/error_prone_annotations-2.3.2.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.3.2/error_prone_annotations-2.3.2-sources.jar",
deps = [],
)
# /private/var/tmp/_bazel_jingwen/877cb1057c2ab3530b2162a72552b72b/external/maven/BUILD:8:1
jvm_import(
name = "com_google_code_findbugs_jsr305",
tags = ["maven_coordinates=com.google.code.findbugs:jsr305:3.0.2"],
jars = ["@maven//:v1/http/uk.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar"],
srcjar = "@maven//:v1/http/uk.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2-sources.jar",
deps = [],
)
要了解更多信息,请查看 Bazel query how-to 页面。