google / j2cl

Java to Closure JavaScript transpiler
Apache License 2.0
1.23k stars 144 forks source link

Bazel package that is both a j2cl_library and java_library #117

Closed AugustNagro closed 3 years ago

AugustNagro commented 3 years ago

Hello,

I have three bazel packages: client, server, and shared.

The client is a j2cl_application, the server is a java_binary, and the shared project should be usable by both, as types are annotated with @JSType.

I've tried a few approaches, and none seem to work.

  1. In the server package, depend on the sharedJs j2cl_library.
  2. Add a new java_library target to the shared package:
java_library(
    name = "sharedJava",
    srcs = glob(["*.java"]),
    visibility = ["//visibility:public"],
)

However, However, it's missing the dependency for the JsType annotations. When I try any of these,

    deps = [
        "@com_google_j2cl//:jsinterop-annotations-j2cl",
#      "@com_google_jsinterop_annotations//:jsinterop-annotations-j2cl"
#      "@com_google_jsinterop_annotations//:jsinterop-annotations-j2cl
    ],

The build fails with something like:

...misplaced here (expected cc_binary, cc_library, genrule, genproto, java_import, java_library, java_proto_library, java_lite_proto_library, proto_library, sh_binary or sh_library) and '@com_google_jsinterop_annotations-j2cl//java/jsinterop/annotations:annotations-j2cl' does not have mandatory providers: 'CcInfo' or 'JavaInfo'...
  1. Add the JSInteropt Annotations as a direct dependency via directions in https://github.com/google/jsinterop-annotations

Any suggestion would be appreciated.. happy holidays!

gkdn commented 3 years ago

Using @com_google_jsinterop_annotations//:jsinterop-annotations should work for a java_library target.

Naming convention wise; j2cl targets have -j2cl suffix and non-j2cl targets (e.g. server) doesn't have suffix.

AugustNagro commented 3 years ago

Huh, thanks, that works!