[BUG] Unable to download correct dependency
Hello,
I spotted a problem when adding a specific dependency to the WORKSPACE file, whose settings are shown below.
###########################
## Java build rules ##
###########################
# Use the latest release from https://github.com/bazelbuild/rules_jvm_external
RULES_JVM_EXTERNAL_TAG = "4.2"
RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca"
http_archive(
name = "rules_jvm_external",
sha256 = RULES_JVM_EXTERNAL_SHA,
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)
load("@rules_jvm_external//:defs.bzl", "maven_install")
maven_install(
artifacts = [
"io.kubernetes:client-java-api:14.0.1",
"io.vavr:vavr:0.10.3",
"org.apache.commons:commons-compress:1.21",
"org.yaml:snakeyaml:1.30",
"com.fasterxml.jackson.core:jackson-databind:2.13.3",
"com.fasterxml.jackson.core:jackson-core:2.13.3",
"io.swagger.codegen.v3:swagger-codegen:3.0.34",
"io.swagger.codegen.v3:swagger-codegen-generators:1.0.34",
"io.swagger.parser.v3:swagger-parser-v3:2.1.1",
"io.swagger.core.v3:swagger-models:2.2.1",
],
fetch_sources = True,
repositories = [
"https://repo1.maven.org/maven2",
],
)
# end maven setup
What happens is that when adding the "io.swagger:codegen.v3:swagger-codegen:3.0.32" (and all other swagger dependencies) the following error is thrown: Error:(793, 11) in deps attribute of jvm_import rule @maven//:io_swagger_swagger_codegen: rule '@maven//:com_atlassian_commonmark_commonmark' does not exist
This is because the target "@maven//:com_atlassian_commonmark_commonmark" is never created - instead what is created is an apparently similar package called "org_commonmark_commonmark". If I add an alias to the maven/BUILD file like so
alias(
name = "com_atlassian_commonmark_commonmark",
actual = "org_commonmark_commonmark",
)
the problem seems to go away. However, as soon as I build the project again, I have to re-do the same procedure.
On the other hand, creating a hello world binary that includes in its deps attributes the atlassian target works fine; therefore it would be worth figuring out why the codegen dependencies make rules_jvm_external do something different.
The maven/BUILD file for the codegen looks like this:
jvm_import(
name = "io_swagger_swagger_codegen",
jars = ["v1/https/repo1.maven.org/maven2/io/swagger/swagger-codegen/2.4.27/swagger-codegen-2.4.27.jar"],
srcjar = "v1/https/repo1.maven.org/maven2/io/swagger/swagger-codegen/2.4.27/swagger-codegen-2.4.27-sources.jar",
deps = [
":com_atlassian_commonmark_commonmark",
":io_swagger_swagger_parser",
":org_slf4j_slf4j_api",
":commons_cli_commons_cli",
":commons_io_commons_io",
":org_apache_commons_commons_lang3",
":com_samskivert_jmustache",
":org_slf4j_slf4j_ext",
":org_json_json",
":io_swagger_swagger_core",
":io_swagger_swagger_compat_spec_parser",
],
tags = [
"maven_coordinates=io.swagger:swagger-codegen:2.4.27",
"maven_url=https://repo1.maven.org/maven2/io/swagger/swagger-codegen/2.4.27/swagger-codegen-2.4.27.jar",
],
)
The error is being thrown because the first of its deps does not exist under that name.
Proposed Solution Indagate what is causing the discrepancy/add an alias.
I found a quick solution to this while waiting for an official fix:
Add the following:
override_targets = {
"com_atlassian_commonmark_commonmark" : "org_commonmark_commonmark",
}
to the maven_install code, under the artifacts list.
Hi, I just stumbled across this exact same issue today. Was the underlying cause ever found?
The override_targets workaround works for me for now