Christian
Christian

Reputation: 7852

Bazel fails to build project when using the maven_jar rule

I've made some refactoring to have this setup function being called from my WORKSPACE file:

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
load("@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies")
load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_jar")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

def setup():
  swift_rules_dependencies()
  apple_rules_dependencies()

  kotlin_repositories()
  kt_register_toolchains()
  go_rules_dependencies()
  go_register_toolchains()

  gazelle_dependencies()
  maven_jar(name = "retrofit",artifact = "com.squareup.retrofit2:retrofit:2.3.0")
  maven_jar(name = "retrofit_converter_jackson", artifact = "com.squareup.retrofit2:converter-jackson:2.3.0")
  maven_jar(name = "jackson_core", artifact = "com.fasterxml.jackson.core:jackson-core:2.9.4")
  maven_jar(name = "jackson_annotations", artifact = "com.fasterxml.jackson.core:jackson-annotations:2.9.4")
  maven_jar(name = "okhttp",artifact = "com.squareup.okhttp3:okhttp:3.6.0")
  maven_jar(name = "jackson_databind", artifact = "com.fasterxml.jackson.core:jackson-databind:2.9.4")
  maven_jar(name = "jackson_datatype_guava", artifact = "com.fasterxml.jackson.datatype:jackson-datatype-guava:2.9.4")
  maven_jar(name = "jackson_module_kotlin", artifact = "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.4")
  maven_jar(name = "google_collections", artifact = "com.google.collections:google-collections:1.0")
  maven_jar(name = "rxjava", artifact = "io.reactivex.rxjava2:rxjava:2.1.13")

It builds on my local machine but on the CI server I get the error jackson_databind requires mvn as a dependency. Please check your PATH.

Before the refactoring i.e. when all of the above was done inside the WORKSPACE file it worked fine (although the maven_jar rule didn't need to be loaded then which I figure it's because it's a workspace rule).

What could be the issue and how do I solve it?

Upvotes: 0

Views: 1620

Answers (1)

Jin
Jin

Reputation: 13473

The native maven_jar is being deprecated, use java_import_external or jvm_maven_import_external instead.

From the GitHub issue tracking the deprecation of this rule:

load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")
jvm_maven_import_external(
    name = "truth",
    artifact = "com.google.truth:truth:0.30",
    artifact_sha256 = "59721f0805e223d84b90677887d9ff567dc534d7c502ca903c0c2b17f05c116a",
    server_urls = ["http://central.maven.org/maven2"],
    licenses = ["notice"],  # Apache 2.0
)

Upvotes: 1

Related Questions