grpc/grpc-java

bazel: Support java_export by adding maven_coordinates to targets

Open

#9,965 创建于 2023年3月20日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)Java (11,124 star) (3,742 fork)batch import
help wanted

描述

What version of gRPC-Java are you using?

1.50.2

What is your environment?

OSX

What did you expect to see?

The pom file generated from a java_export when using GRPC includes GRPC dependencies rather than inlining them into the generate jar file.

What did you see instead?

The pom file does NOT include a grpc dependency. The generate jar includes directly grpc classes. For example: io/grpc/Attributes.java, io/grpc/util/AdvancedTlsX509KeyManager.java, io/grpc/stub/AbstractAsyncStub.java

Steps to reproduce the bug

  1. Create a java bazel project following the canonical example
  2. Add a java_export rule, see below.
  3. Run the publish rule: bazel run --define "maven_repo=file://$HOME/.m2/repository" //export_test:export_test.publish
  4. Examine the resulting pom file and artifact
  • jar tf ~/.m2/repository/com/example/exporttest/0.0.1/exporttest-0.0.1-sources.jar|less
  • less ~/m2/repository/com/example/exporttest/0.0.1/exporttest-0.0.1.pom
  1. Observe that protobuf and grpc dependencies are omitted from the pom file
  2. Observe that protobuf and grpc classes are in the jar file
java_export(
    name = "export_test",
    maven_coordinates = "com.example:exporttest:0.0.1",
    runtime_deps = [
        "//export_test_lib",
        "@maven//:com_google_protobuf_protobuf_java",
        "@maven//:com_google_protobuf_protobuf_java_util",
        "@maven//:io_grpc_grpc_api",
        "@maven//:io_grpc_grpc_core",
        "@maven//:io_grpc_grpc_protobuf",
        "@maven//:io_grpc_grpc_stub",
    ],
)

Workaround

Simply removing IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS, added here, seems to work fine.

Alternatively, perhaps someone could set the maven_coordinates tags so that java_export knows which artifacts to reference!

贡献者指南

bazel: Support java_export by adding maven_coordinates to targets · grpc/grpc-java#9965 | Good First Issue