rules_jvm_external icon indicating copy to clipboard operation
rules_jvm_external copied to clipboard

Zip artifact labels are used, but zip artifact targets aren't generated in maven BUILD file

Open ahumesky opened this issue 3 years ago • 1 comments

If an artifact depends on a zip artifact, then rules_jvm_external will generate targets that depend on the zip artifacts by label, but no targets are generated for those zip artifacts in the BUILD file.

For example https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-ri/3.0.2 depends on https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-release-documentation/3.0.2 and https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-samples/3.0.2 which are zips.

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

RULES_JVM_EXTERNAL_TAG = "4.2"
RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca"

http_archive(
    name = "rules_jvm_external",
    strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
    sha256 = RULES_JVM_EXTERNAL_SHA,
    url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
rules_jvm_external_deps()
load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
rules_jvm_external_setup()

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
    artifacts = [
        "com.sun.xml.bind:jaxb-ri:3.0.2",
    ],
    repositories = [
        "https://repo1.maven.org/maven2",
    ],
)

Running

bazel build @maven//:com_sun_xml_bind_jaxb_ri

results in

in exports attribute of java_library rule @maven//:com_sun_xml_bind_jaxb_ri: rule '@maven//:com_sun_xml_bind_jaxb_samples_zip' does not exist. Since this rule was created by the macro 'java_library', the error might have been caused by the macro implementation

And in the BUILD file, zip targets are used but the targets themselves are not defined:

$ grep zip $(bazel info output_base)/external/maven/BUILD
		":com_sun_xml_bind_jaxb_samples_zip",
		":com_sun_xml_bind_jaxb_release_documentation_zip_docbook",

ahumesky avatar Feb 22 '22 21:02 ahumesky

One workaround is to exclude the zip artifacts (assuming the code doesn't need them):

maven_install(
    artifacts = [
        "com.sun.xml.bind:jaxb-ri:3.0.2",
    ],
    excluded_artifacts = [
        "com.sun.xml.bind:jaxb-samples",
        "com.sun.xml.bind:jaxb-release-documentation",
    ],
    repositories = [
        "https://repo1.maven.org/maven2",
    ],
)

ahumesky avatar Feb 22 '22 21:02 ahumesky