Use the Maven artifact ID as the canonical_id in jvm_maven_import_external.

This affects how downloaded Maven artifacts are looked up from the cache. Before this, cache lookups would only be based on the hash. So changing the artifact ID (like bumping the version) but forgetting to change the hash would result in the cache lookup silently fetching the old version (with the matching hash).

Now, the cache lookup will use the artifact ID and the hash, so bumping the artifact ID but forgetting to update the hash will result in a cache miss, a redownload of the artifact, and an error when the hash doesn't match.

This canonical_id parameter was added for exactly this purpose in https://github.com/bazelbuild/bazel/commit/c917ab208942e7b250e4dc928863a56ea2bdaee3 and https://github.com/bazelbuild/bazel/issues/5144

Fixes https://github.com/bazelbuild/bazel/issues/10353

PiperOrigin-RevId: 318830199
diff --git a/tools/build_defs/repo/jvm.bzl b/tools/build_defs/repo/jvm.bzl
index cf32d34..8c27eed 100644
--- a/tools/build_defs/repo/jvm.bzl
+++ b/tools/build_defs/repo/jvm.bzl
@@ -106,9 +106,19 @@
         lines.append(extra)
         if not extra.endswith("\n"):
             lines.append("")
-    repository_ctx.download(urls, path, sha)
+    repository_ctx.download(
+        urls,
+        path,
+        sha,
+        canonical_id = repository_ctx.attr.canonical_id,
+    )
     if srcurls and _should_fetch_sources_in_current_env(repository_ctx):
-        repository_ctx.download(srcurls, srcpath, srcsha)
+        repository_ctx.download(
+            srcurls,
+            srcpath,
+            srcsha,
+            canonical_id = repository_ctx.attr.canonical_id,
+        )
     repository_ctx.file("BUILD", "\n".join(lines))
     repository_ctx.file("%s/BUILD" % extension, "\n".join([
         _HEADER,
@@ -223,6 +233,7 @@
         "additional_rule_attrs": attr.string_dict(),
         "srcjar_urls": attr.string_list(),
         "srcjar_sha256": attr.string(),
+        "canonical_id": attr.string(),
         "deps": attr.string_list(),
         "runtime_deps": attr.string_list(),
         "testonly_": attr.bool(),
@@ -274,6 +285,7 @@
     jvm_import_external(
         artifact_urls = jar_urls,
         srcjar_urls = srcjar_urls,
+        canonical_id = artifact,
         rule_name = rule_name,
         rule_load = rule_load,
         tags = tags,