简体   繁体   中英

In Bazel, fetching jar from private maven repository fails with 403

I am trying to build a simple java project with Bazel, using rules_jvm_external. Some of the dependencies are kept in a private maven repository. My WORKSPACE looks like this:

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

RULES_JVM_EXTERNAL_TAG = "3.2"
RULES_JVM_EXTERNAL_SHA = "82262ff4223c5fda6fb7ff8bd63db8131b51b413d26eb49e3131037e79e324af"

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//:defs.bzl", "maven_install")

maven_install(
    name = "maven_deps",
    artifacts = [
        "org.projectlombok:lombok:1.18.12",
        "mygroup:myartifact:version"
    ],
    repositories = [
        "https://repo1.maven.org/maven2",
        "https://username:password@my.repo.io/artifactory/repo",
    ],
)

My BUILD looks like this:

java_library(
    name = "mylib",
    srcs = glob([
        "proj/src/main/java/**/*.java"
    ]),
    deps = [
        "@maven_deps//:org_projectlombok_lombok",
        "@maven_deps//:mygroup_myartifact",
    ],
)

When i run bazel build //:mylib the fetching of mygroup:myartifact:version from the private maven repository fails with http error code 403. I hardcoded the username and password for simplicity. The username used is an email so i encoded it, eg: me%40gmail.com . I am using bazel version 3.1.0. Passing the username and password through env vars produced the same error. Fetching the same jar using curl works great:

curl -O 'https://me%40gmail:PASSWORD@my.repo.io/artifactory/repo/mygroup/myartifcat-version.jar'

Can anyone see what the problem is? Thank you in advance!

If I recall correctly, Bazel's maven_install from rules_jvm_external relies on Coursera Coursier * for fetching dependencies. Where I work at, we rely on a property file containing the credentials at the correct location for your OS.

Try setting this:

simple.username=<username>
simple.password=<password>
simple.host=my.repo.io

In either /.config/coursier/credentials.properties (if you are on Linux) or ~/Library/Preferences/Coursier/credentials.properties on OS X.

(*) https://github.com/bazelbuild/rules_jvm_external/blob/master/docs/api.md mentions Coursier indeed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM