Repository: bazelbuild/bazel
Issue: @bazel_tools//third_party/jarjar was removed
Labels: P1
team-Rules-Java

### Description of the problem / feature request:
androidx.test (github/android/android_test) is broken HEAD with bazel 0.23.2 with the following error:
Step #2: ERROR: /workspace/ext/junit/java/androidx/test/ext/junit/BUILD.bazel:38:1: no such package '@bazel_tools//third_party/jarjar': BUILD file not found on package path and referenced by '//ext/junit/java/androidx/test/ext/junit:junit_release_jarjared'

It looks like @bazel_tools//third_party/jarjar has moved. 

I chatted with @jin , he suggested filing an issue since this is a breaking change

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

See https://github.com/android/android-test/blob/master/CONTRIBUTING.md
bazel build :axt_m2repository


### What operating system are you running Bazel on?

linux

### What's the output of `bazel info release`?

release 0.23.2


### Any other information, logs, or outputs that you want to share?



Issue comments:
@iirina could you take a look please?
You can use a newer version of jarjar with the following repos/build targets:
```python
JCENTER = "http://jcenter.bintray.com"
jvm_maven_import_external(
    name = "com_google_jarjar",
    licenses = ["notice"],
    artifact = "org.pantsbuild:jarjar:1.6.6",
    artifact_sha256 = "965ab4c68b7ff6164841d7034cf5b0d5397205e35903c372db981a3660ad72f1",
    server_urls = [JCENTER],
    deps = [
        "@org_ow2_asm_asm",
    ],
)
jvm_maven_import_external(
    name = "org_ow2_asm_asm",
    licenses = ["notice"],
    artifact = "org.ow2.asm:asm:6.2",
    server_urls = [JCENTER],
    deps = [
        "@org_ow2_asm_asm_commons",
    ],
)
jvm_maven_import_external(
    name = "org_ow2_asm_asm_commons",
    licenses = ["notice"],
    artifact = "org.ow2.asm:asm-commons:6.2",
    server_urls = [JCENTER],
)


java_binary(
    name = "jarjar",
    create_executable = True,
    main_class = "org.pantsbuild.jarjar.Main",
    visibility = ["//visibility:public"],
    runtime_deps = [
        "@com_google_jarjar",
    ]
)
```
@brettchabot indeed jarjar was moved out of the bazel binary as part of the effort to move the Java tools to a remote repository. I'll send a PR to re-add the targets, but they will refrence JarJar from the remote tools.
@iirina what is the new target one should use ?
@steeve you can use  `@remote_java_tools_linux//:JarJar`
@iirina it seems on my machine (macos) it's `@remote_java_tools_darwin//:JarJar`. It makes it hard to depend on since the repo name has the os inside :(
You can add an alias if you want:

```
alias(
    name = JarJar,
   actual =  select({
        "@bazel_tools//src/conditions:linux_x86_64": ["@remote_java_tools_linux//:JarJar"],
        "@bazel_tools//src/conditions:darwin": ["@remote_java_tools_darwin//:JarJar"],
        "@bazel_tools//src/conditions:darwin_x86_64": ["@remote_java_tools_darwin//:JarJar"],
        "@bazel_tools//src/conditions:windows": ["@remote_java_tools_windows//:JarJar"],
        # Any repository can be used.
        "@bazel_tools//conditions:default": ["@remote_java_tools_linux//:JarJar"],
    })
)
```

or use any of the repos since JarJar is a deploy jar and is platform agnostic:

```
alias(
    name = "JarJar",
    actual = "@remote_java_tools_darwin//:JarJar"
)

That's great thank you !
> @steeve you can use `@remote_java_tools_linux//:JarJar`

@iirina , I am not able to see the JarJar target now. I can see only the below

jenkins@bazel5-d57575cd6-sdxvb:~/repo$ tools/bazel query "@remote_java_tools_linux//:*"
Another command (pid=29262) is running. Waiting for it to complete on the server (server_pid=9187)...
@remote_java_tools_linux//:BUILD
@remote_java_tools_linux//:ijar_prebuilt_binary
@remote_java_tools_linux//:java_tools/ijar/ijar
@remote_java_tools_linux//:java_tools/ijar/ijar.exe
@remote_java_tools_linux//:java_tools/src/tools/singlejar/singlejar_local
@remote_java_tools_linux//:java_tools/src/tools/singlejar/singlejar_local.exe
@remote_java_tools_linux//:prebuilt_singlejar
@remote_java_tools_linux//:windows
Loading: 1 packages loaded
jenkins@bazel5-d57575cd6-sdxvb:~/repo$ 

Did this get moved somewhere else?
I am using bazel 6.4.0

Pull request review comments:

Patch that resolved the issue:
diff --git a/src/BUILD b/src/BUILD
index 111a1e26e7b2f3..ec9c7870096f28 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -124,6 +124,7 @@ JAVA_TOOLS = [
     "//src/tools/singlejar:embedded_tools",
     "//src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps:embedded_tools",
     "//third_party/java/jacoco:srcs",
+    "//third_party/jarjar:embedded_build_and_license",
 ] + select({
     "//src/conditions:arm": [],
     "//conditions:default": [
diff --git a/src/create_embedded_tools.py b/src/create_embedded_tools.py
index dfb7b11c98ac0e..3d64886898d85c 100644
--- a/src/create_embedded_tools.py
+++ b/src/create_embedded_tools.py
@@ -44,6 +44,8 @@
     ('*def_parser.exe', lambda x: 'tools/def_parser/def_parser.exe'),
     ('*zipper.exe', lambda x: 'tools/zip/zipper/zipper.exe'),
     ('*zipper', lambda x: 'tools/zip/zipper/zipper'),
+    ('*third_party/jarjar/BUILD.tools', lambda x: 'third_party/jarjar/BUILD'),
+    ('*third_party/jarjar/LICENSE', lambda x: 'third_party/jarjar/LICENSE'),
     ('*src/objc_tools/*',
      lambda x: 'tools/objc/precomp_' + os.path.basename(x)),
     ('*xcode*StdRedirect.dylib', lambda x: 'tools/objc/StdRedirect.dylib'),
diff --git a/third_party/jarjar/BUILD b/third_party/jarjar/BUILD
index 6dc81a18e414d9..2d25947b9fdab8 100644
--- a/third_party/jarjar/BUILD
+++ b/third_party/jarjar/BUILD
@@ -7,6 +7,14 @@ filegroup(
     srcs = glob(["**"]),
 )
 
+filegroup(
+    name = "embedded_build_and_license",
+    srcs = [
+        "BUILD.tools",
+        "LICENSE",
+    ],
+)
+
 # jarjar_bin
 java_binary(
     name = "jarjar_command",
diff --git a/third_party/jarjar/BUILD.tools b/third_party/jarjar/BUILD.tools
new file mode 100644
index 00000000000000..3c759aa63c03ae
--- /dev/null
+++ b/third_party/jarjar/BUILD.tools
@@ -0,0 +1,19 @@
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])  # Apache 2.0
+
+load(
+    "//tools/jdk:remote_java_tools_aliases.bzl",
+    "remote_java_tools_java_import",
+)
+
+remote_java_tools_java_import(
+    name = "jarjar_import",
+    target = ":JarJar",
+)
+
+java_binary(
+    name = "jarjar_bin",
+    main_class = "com.tonicsystems.jarjar.Main",
+    runtime_deps = [":jarjar_import"],
+)
diff --git a/tools/jdk/BUILD b/tools/jdk/BUILD
index ecd2fa784a5b51..15376a4dba3c47 100644
--- a/tools/jdk/BUILD
+++ b/tools/jdk/BUILD
@@ -1,17 +1,17 @@
 load(
     "//tools/jdk:default_java_toolchain.bzl",
-    "default_java_toolchain",
-    "java_runtime_files",
     "JDK8_JVM_OPTS",
     "bootclasspath",
+    "default_java_toolchain",
+    "java_runtime_files",
 )
 load(
     "//tools/jdk:java_toolchain_alias.bzl",
-    "java_toolchain_alias",
-    "java_runtime_alias",
     "java_host_runtime_alias",
-    "legacy_java_toolchain_alias",
+    "java_runtime_alias",
+    "java_toolchain_alias",
     "legacy_java_runtime_alias",
+    "legacy_java_toolchain_alias",
 )
 load(
     "//tools/jdk:remote_java_tools_aliases.bzl",
@@ -405,9 +405,9 @@ alias(
     actual = "//third_party/java/jacoco:blaze-agent",
 )
 
-java_import(
+remote_java_tools_java_import(
     name = "JarJar",
-    jars = [":jarjar_command_deploy.jar"],
+    target = ":JarJar",
 )
 
 test_suite(


Test patch: