API Reference

Basic functions

These are the basic functions to get started.

To use these functions, load them at the top of your BUILD file. For example:

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

maven_install

Resolves and fetches artifacts transitively from Maven repositories.

This macro runs a repository rule that invokes the Coursier CLI to resolve and fetch Maven artifacts transitively.

PARAMETERS

NameDescriptionDefault Value
nameA unique name for this Bazel external repository.“maven”
repositoriesA list of Maven repository URLs, specified in lookup order.

Supports URLs with HTTP Basic Authentication, e.g. “https://username:password@example.com”.
[]
artifactsA list of Maven artifact coordinates in the form of group:artifact:version.[]
fail_on_missing_checksum - True
fetch_sourcesAdditionally fetch source JARs.False
use_unsafe_shared_cacheDownload artifacts into a persistent shared cache on disk. Unsafe as Bazel is currently unable to detect modifications to the cache.False
excluded_artifactsA list of Maven artifact coordinates in the form of group:artifact to be excluded from the transitive dependencies.[]
generate_compat_repositoriesAdditionally generate repository aliases in a .bzl file for all JAR artifacts. For example, @maven//:com_google_guava_guava can also be referenced as @com_google_guava_guava//jar.False
version_conflict_policyPolicy for user-defined vs. transitive dependency version conflicts. If “pinned”, choose the user‘s version unconditionally. If “default”, follow Coursier’s default policy.“default”
maven_install_jsonA label to a maven_install.json file to use pinned artifacts for generating build targets. e.g //:maven_install.json.None
override_targetsA mapping of group:artifact to Bazel target labels. All occurrences of the target label for group:artifact will be an alias to the specified label, therefore overriding the original generated jvm_import or aar_import target.{}
strict_visibilityControls visibility of transitive dependencies. If True, transitive dependencies are private and invisible to user‘s rules. If False, transitive dependencies are public and visible to user’s rules.False
resolve_timeoutThe execution timeout of resolving and fetching artifacts.600
jetifyRuns the AndroidX jetifier tool on all artifacts.False

Maven specification functions

These are helper functions to specify more information about Maven artifacts and repositories in maven_install.

To use these functions, load the maven struct at the top of your BUILD file:

load("@rules_jvm_external//:specs.bzl", "maven")

maven.repository

Generates the data map for a Maven repository specifier given the available information.

If both a user and password are given as arguments, it will include the access credentials in the repository spec. If one or both are missing, it will just generate the repository url.

PARAMETERS

NameDescriptionDefault Value
urlA string containing the repository url (ex: “https://maven.google.com/”).none
userA username for this Maven repository, if it requires authentication (ex: “johndoe”).None
passwordA password for this Maven repository, if it requires authentication (ex: “example-password”).None

maven.artifact

Generates the data map for a Maven artifact given the available information about its coordinates.

PARAMETERS

NameDescriptionDefault Value
groupThe Maven artifact coordinate group name (ex: “com.google.guava”).none
artifactThe Maven artifact coordinate artifact name (ex: “guava”).none
versionThe Maven artifact coordinate version name (ex: “27.0-jre”).none
packagingThe Maven packaging specifier (ex: “jar”).None
classifierThe Maven artifact classifier (ex: “javadoc”).None
override_license_typesAn array of Bazel license type strings to use for this artifact's rules (overrides autodetection) (ex: [“notify”]).None
exclusionsAn array of exclusion objects to create exclusion specifiers for this artifact (ex: maven.exclusion(“junit”, “junit”)).None
neverlinkDetermines if this artifact should be part of the runtime classpath.None
testonlyDetermines whether this artifact is available for targets not marked as testonly = True.None

maven.exclusion

Generates the data map for a Maven artifact exclusion.

PARAMETERS

NameDescriptionDefault Value
groupThe Maven group name of the dependency to exclude, e.g. “com.google.guava”.none
artifactThe Maven artifact name of the dependency to exclude, e.g. “guava”.none