bazelbuild / rules_jvm_external

Bazel rules to resolve, fetch and export Maven artifacts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bazel cannot find Pinned json file because it assumes there is a Build

KaoruDev opened this issue · comments

Problem

When starting up bazel, I see this error:

Unable to load package for //:maven_install.json: BUILD file not found in any of the following directories.
 - /path/to/project

WORKSPACE file

rules_scala_version="acac888c86e79110d1d08ab5578a7d0101c97963" # update this as needed

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "io_bazel_rules_scala",
    strip_prefix = "rules_scala-%s" % rules_scala_version,
    type = "zip",
    url = "https://github.com/bazelbuild/rules_scala/archive/%s.zip" % rules_scala_version,
)

load("@io_bazel_rules_scala//scala:toolchains.bzl", "scala_register_toolchains")
scala_register_toolchains()

load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
scala_repositories()

protobuf_version="09745575a923640154bcf307fba8aedff47f240a"
protobuf_version_sha256="416212e14481cff8fd4849b1c1c1200a7f34808a54377e22d7447efdf54ad758"

http_archive(
    name = "com_google_protobuf",
    url = "https://github.com/protocolbuffers/protobuf/archive/%s.tar.gz" % protobuf_version,
    strip_prefix = "protobuf-%s" % protobuf_version,
    sha256 = protobuf_version_sha256,
)

# bazel-skylib 0.8.0 released 2019.03.20 (https://github.com/bazelbuild/bazel-skylib/releases/tag/0.8.0)
skylib_version = "0.8.0"
http_archive(
    name = "bazel_skylib",
    type = "tar.gz",
    url = "https://github.com/bazelbuild/bazel-skylib/releases/download/{}/bazel-skylib.{}.tar.gz".format (skylib_version, skylib_version),
    sha256 = "2ef429f5d7ce7111263289644d233707dba35e39696377ebab8b0bc701f7818e",
)

scala_repositories((
    "2.12.8",
    {
       "scala_compiler": "f34e9119f45abd41e85b9e121ba19dd9288b3b4af7f7047e86dc70236708d170",
       "scala_library": "321fb55685635c931eba4bc0d7668349da3f2c09aee2de93a70566066ff25c28",
       "scala_reflect": "4d6405395c4599ce04cea08ba082339e3e42135de9aae2923c9f5367e957315a"
    }
))

RULES_JVM_EXTERNAL_TAG = "2.7"
RULES_JVM_EXTERNAL_SHA = "f04b1466a00a2845106801e0c5cec96841f49ea4e7d1df88dc8e4bf31523df74"

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")

dropwizards_version = "4.1.0"

maven_install(
    name = "maven",
    artifacts = [
        "ch.qos.logback:logback-classic:1.2.3",
        "ch.qos.logback:logback-core:1.2.3",
        "com.beachape:enumeratum_2.12:1.5.12",
        "com.typesafe:config:1.3.4",
        "io.dropwizard.metrics:metrics-core:%s" % dropwizards_version,
        "io.dropwizard.metrics:metrics-healthchecks:%s" % dropwizards_version,
        "io.dropwizard.metrics:metrics-jvm:%s" % dropwizards_version,
        "io.dropwizard.metrics:metrics-logback:%s" % dropwizards_version,
        "joda-time:joda-time:2.10.1",
        "nl.grons:metrics-scala_2.12:4.0.0",
        "org.clapper:grizzled-slf4j_2.12:1.3.4",
        "org.coursera:metrics-datadog:1.1.14",
        "org.coursera:metrics-datadog:1.1.12",
        "org.hamcrest:hamcrest-all:1.3",
        "org.joda:joda-convert:1.8.1",
        "org.mindrot:jbcrypt:0.4",
        "org.mockito:mockito-core:2.24.0",
        "org.scalatest:scalatest_2.12:3.0.5",
        "org.slf4j:slf4j-api:1.7.26",
        "org.slf4j:jul-to-slf4j:1.7.25",
        "commons-logging:commons-logging:1.2",
        "net.logstash.logback:logstash-logback-encoder:6.1",
    ],
    repositories = [
        "https://central.maven.org/maven2/",
        "https://jcenter.bintray.com/"
    ],
    fetch_sources = True,
    maven_install_json = "//:maven_install.json"
)
load("@maven//:defs.bzl", "pinned_maven_install")
pinned_maven_install()

Bazel Version:

Build label: 0.28.1
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jul 19 15:22:50 2019 (1563549770)
Build timestamp: 1563549770
Build timestamp as int: 1563549770

Workaround

  • moved maven_install.json to external/maven_install.json
  • changed maven_install_json = "//:maven_install.json" to maven_install_json = "maven_install.json"

creating an empty BUILD file in the top directory seems to fix this issue too. Not sure if these instructions should be made more clear in the README? If so I'd be happy to open a PR.

commented

creating an empty BUILD file in the top directory seems to fix this issue too. Not sure if these instructions should be made more clear in the README? If so I'd be happy to open a PR.

This is the recommended way. We haven't ran into this issue because most projects have a top level BUILD file. Sorry for missing it out on the documentation - happy to take a PR for this!

commented

Actually, if this works:

changed maven_install_json = "//:maven_install.json" to maven_install_json = "maven_install.json"

it's a better user experience since it'll work for all projects with or without a top level BUILD file.

so maven_install_json = maven_install.json only works if you move maven_install.json to external/maven_install.json

I'm not sure exactly what the external directory is meant to represent.

This is what the doc currently says:

      external/                           <== The directory that remote repositories are
                                              downloaded/symlinked into.

I think just explicitly calling out having a top-level BUILD file may work might be okay for now.

commented

so maven_install_json = maven_install.json only works if you move maven_install.json to external/maven_install.json

Ahh, right. The external directory represents a special package in the context of repository rules, like maven_install.

Let's go with the recommendation of the top level BUILD file.