google / j2cl

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

How do I add com.google.gwt:gwt-user as a dependency? #119

Closed victorjoh closed 3 years ago

victorjoh commented 3 years ago

I want to transpile Java code that uses the java.util.regex.Pattern class. But since that JRE class is unsupported (not included here: http://www.gwtproject.org/doc/latest/RefJreEmulation.html), I thought I could use com.google.gwt.regexp.shared.RegExp instead.

I extended the hello world sample and added the dependency in the WORKSPACE file like this, similar to the guava sample:

j2cl_maven_import_external(
    name = "com_google_gwt_user-j2cl",
    artifact = "com.google.gwt:gwt-user:2.9.0",
    server_urls = _MAVEN_CENTRAL_URLS,
)

and I added dependency to the j2cl_library rule in the BUILD file like this:

j2cl_library(
    name = "app",
    srcs = glob([
        "*.java",
        "*.js",
    ]),
    deps = [
        "@com_google_gwt_user-j2cl",
        "@com_google_j2cl//:jsinterop-annotations-j2cl",
    ],
)

but when building I get the following error:

ERROR: /home/victor/.cache/bazel/_bazel_victor/5657afe6a5a2554625b50ec0fc3b9a80/external/com_google_gwt_user-j2cl/BUILD:10:13: Compiling Java headers external/com_google_gwt_user-j2cl/libcom_google_gwt_user-j2cl-hjar.jar (1 source jar) failed (Exit 1): java failed: error executing command external/remotejdk11_linux/bin/java -Xverify:none '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED' ... (remaining 35 argument(s) skipped)
external/com_google_gwt_user-j2cl/com/google/gwt/core/translatable/com/google/gwt/core/client/impl/JavaScriptExceptionBase.java:24: error: duplicate declaration of com.google.gwt.core.client.impl.JavaScriptExceptionBase
public class JavaScriptExceptionBase extends JsException {
             ^

Can you please tell what I am doing wrong?

I am using Bazelisk v1.7.3

tbroyer commented 3 years ago

You can't use gwt-user with J2CL, and I believe you couldn't use com.google.gwt.regexp anyway because I think it uses JSNI.

You should be able to use https://github.com/gwtproject/gwt-regexp (org.gwtproject.regexp) though: https://search.maven.org/artifact/org.gwtproject.regexp/gwt-regexp

victorjoh commented 3 years ago

Thank you, that worked.

I added that dependency like this in the WORKSPACE file:

j2cl_maven_import_external(
    name = "org_gwtproject_regexp-j2cl",
    artifact = "org.gwtproject.regexp:gwt-regexp:1.0.0-RC1",
    server_urls = _MAVEN_CENTRAL_URLS,
    deps = [
        "@com_google_jsinterop_base//:jsinterop-base-j2cl",
        "@com_google_elemental2//:elemental2-core-j2cl",
    ],
)