Can't call "maven.install" when configure "rules_jvm_external" 6.6 from bzlmod file
Hi, When configuring "rules_jvm_external" with new bzlmod syntax, I can't use some of the maven dependencies together with junit. The build fails with the following error:
ERROR: /usr/local/google/home/ktimofeev/.cache/bazel/_bazel_ktimofeev/a7e309cc39a88b2dfa98eb01f2931cab/external/rules_jvm_external~~maven~maven/BUILD:122:11: in aar_import rule @@rules_jvm_external~~maven~maven//:androidx_test_runner: non-test target '@@rules_jvm_external~~maven~maven//:androidx_test_runner' depends on testonly target '@@rules_jvm_external~~maven~maven//:junit_junit' and doesn't have testonly attribute set
ERROR: /usr/local/google/home/ktimofeev/.cache/bazel/_bazel_ktimofeev/a7e309cc39a88b2dfa98eb01f2931cab/external/rules_jvm_external~~maven~maven/BUILD:122:11: Analysis of target '@@rules_jvm_external~~maven~maven//:androidx_test_runner' failed
ERROR: Analysis of target '//:android_lib_with_deps' failed; build aborted: Analysis failed
It seems like the target generated for androidx_test_runner dependency miss the testonly= argument, or the junit has it wrongly specified.
However, if we configure the same deps using WORKSPACE syntax everything builds fine.
The interesting thing is, that if we use WORKSPACE syntax, the testonly= argument is not set for junit and is not required for the android_binary that depends on junit.
Please see this repository for the reproducer: https://github.com/KirillTim/rules_jvm_external_workspace_testonly
rules_jvm_external is version 6.6
bazel is version 7.4.1
The relevant issue: https://github.com/bazel-contrib/rules_jvm_external/issues/1225
This is caused by the bazel_worker_java bzlmod introducing its own junit deps, which is marked testonly, into the maven namespace:
https://github.com/bazelbuild/bazel-worker-api/blob/3dfa3826c7e5706391aa1af9382c1ed3507e154b/java/MODULE.bazel#L21-L38
I think the right fix here is to update the bazel_worker_java to not introduce its test deps into @maven.