bazelbuild / migration-tooling

Migration tools for Bazel
Apache License 2.0
44 stars 30 forks source link

Generated libraries from maven should export transitive dependencies #90

Open ceronman opened 5 years ago

ceronman commented 5 years ago

The generate_workspace tool generates both maven_jar targets and also java_library targets.

The java_library targets seem to contain transitive dependencies, for example, when generating dependencies for the org.asynchttpclient:async-http-client:2.5.2 artifact, I see that a java_library target is created that looks like this:

  native.java_library(
      name = "org_asynchttpclient_async_http_client",
      visibility = ["//visibility:public"],
      exports = ["@org_asynchttpclient_async_http_client//jar"],
      runtime_deps = [
          ":com_sun_activation_javax_activation",
          ":com_typesafe_netty_netty_reactive_streams",
          ":io_netty_netty_buffer",
          ":io_netty_netty_codec",
          ":io_netty_netty_codec_dns",
          ":io_netty_netty_codec_http",
          ":io_netty_netty_codec_socks",
          ":io_netty_netty_common",
          ":io_netty_netty_handler",
          ":io_netty_netty_handler_proxy",
          ":io_netty_netty_resolver",
          ":io_netty_netty_resolver_dns",
          ":io_netty_netty_transport",
          ":io_netty_netty_transport_native_epoll",
          ":io_netty_netty_transport_native_unix_common",
          ":org_asynchttpclient_async_http_client_netty_utils",
          ":org_reactivestreams_reactive_streams",
          ":org_slf4j_slf4j_api",
      ],
  )

At first glance, it seems very handy to have these generated java_library targets containing all the transitive dependencies of a given maven jar. However, given that these are declared as runtime_deps, the generated library is not very useful because I can't use it as a single dependency in other targets. I still need to include all the transitive dependencies manually. So I don't understand the point of generated java_libray targets as maven_jars could be used directly.

One solution to this problem would be to make the java_library targets export the transitive dependencies. For example like this:

  native.java_library(
      name = "org_asynchttpclient_async_http_client",
      visibility = ["//visibility:public"],
      exports = [
          "@org_asynchttpclient_async_http_client//jar"
          "@com_sun_activation_javax_activation//jar",
          "@com_typesafe_netty_netty_reactive_streams//jar",
          "@io_netty_netty_buffer//jar",
          "@io_netty_netty_codec//jar",
          "@io_netty_netty_codec_dns//jar",
          "@io_netty_netty_codec_http//jar",
          "@io_netty_netty_codec_socks//jar",
          "@io_netty_netty_common//jar",
          "@io_netty_netty_handler//jar",
          "@io_netty_netty_handler_proxy//jar",
          "@io_netty_netty_resolver//jar",
          "@io_netty_netty_resolver_dns//jar",
          "@io_netty_netty_transport//jar",
          "@io_netty_netty_transport_native_epoll//jar",
          "@io_netty_netty_transport_native_unix_common//jar",
          "@org_asynchttpclient_async_http_client_netty_utils//jar",
          "@org_reactivestreams_reactive_streams//jar",
          "@org_slf4j_slf4j_api//jar",
      ],
  )

In this way, I could easily declare org_asynchttpclient_async_http_client as my dep and make sure all it's transitive dependencies will come with it.

Note: I'm new to Bazel. I apologize if this doesn't make sense :)

oferb commented 5 years ago

You can have a look at how it's done here: https://github.com/google/startup-os/tree/master/tools/deps

It's based on johnynek/bazel-deps. See this issue on a comparison between bazelbuild/migration-tooling and johnynek/bazel-deps.