### Example libs.versions.toml file
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod.md
An example TOML file demonstrating how to declare versions and libraries for a Gradle version catalog.
```toml
[versions]
junitJupiter = "5.12.2"
[libraries]
guava = { module = "com.google.guava:guava" }
guavaBom = { module = "com.google.guava:guava-bom", version = "33.4.8-jre" }
junitApi = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junitJupiter" }
```
--------------------------------
### Install Android Command Line Tools on macOS
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Installs necessary Android SDK components using Homebrew and sets up ANDROID_HOME and ANDROID_NDK_HOME environment variables.
```bash
brew install android-commandlinetools
export ANDROID_HOME="$(brew --prefix)/share/android-commandlinetools"
sdkmanager "build-tools;33.0.1" "cmdline-tools;latest" "ndk;21.4.7075529" "platform-tools" "platforms;android-33"
export ANDROID_NDK_HOME="$ANDROID_HOME/ndk/21.4.7075529"
```
--------------------------------
### Example Bazel Add Module Interactive Run
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/RELEASING.md
This is an example of an interactive session when running `bazel run //tools:add_module`. It shows the prompts for module information, source archive details, and build/test targets.
```shell
% bazel run tools:add_module main*
INFO: Invocation ID: aa3e5952-e546-4ba5-a30a-7333c05a47e3
INFO: Analyzed target //tools:add_module (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //tools:add_module up-to-date:
bazel-bin/tools/add_module
INFO: Elapsed time: 0.076s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/tools/add_module
INFO: Getting module information from user input...
ACTION: Please enter the module name: rules_jvm_external
ACTION: Please enter the module version: 5.1
ACTION: Please enter the compatibility level [default is 1]:
ACTION: Please enter the URL of the source archive: https://github.com/bazelbuild/rules_jvm_external/releases/download/5.0/rules_jvm_external-5.1.tar.gz
ACTION: Please enter the strip_prefix value of the archive [default None]: rules_jvm_external-5.1
ACTION: Do you want to add patch files? [y/N]: n
ACTION: Do you want to add a BUILD file? [y/N]: n
ACTION: Do you want to specify a MODULE.bazel file? [y/N]: y
ACTION: Please enter the MODULE.bazel file path: /Volumes/Dev/src/github.com/bazelbuild/rules_jvm_external/MODULE.bazel
ACTION: Do you want to specify an existing presubmit.yml file? (See https://github.com/bazelbuild/bazel-central-registry/tree/main#presubmityml) [y/N]:
ACTION: Please enter a list of build targets you want to expose to downstream users, separated by `,`: @rules_jvm_external//:implementation,@rules_jvm_external//private/tools/java/...
ACTION: Do you have a test module in your source archive? [Y/n]: y
ACTION: Please enter the test module path in your source archive: examples/bzlmod
ACTION: Please enter a list of build targets for the test module, separated by `,`: //java/src/com/github/rules_jvm_external/examples/bzlmod:bzlmod_example
ACTION: Please enter a list of test targets for the test module, separated by `,`:
```
--------------------------------
### Maven Install Configuration
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod-api.md
Configuration options for the `install` rule, which combines artifact and BOM declarations with lock file locations and artifact repositories.
```APIDOC
## install
Combines artifact and bom declarations with setting the location of lock files to use, and repositories to download artifacts from. There can only be one `install` tag with a given `name` per module. `install` tags with the same name across multiple modules will be merged, with the root module taking precedence.
### Attributes
- **name** (Name) - Optional - Default: `"maven"` - A unique name for the install configuration.
- **aar_import_bzl_label** (String) - Optional - Default: `"@rules_android//rules:rules.bzl"` - The label to use for importing `aar_import`.
- **additional_coursier_options** (List of strings) - Optional - Default: `[]` - Additional options passed to Coursier.
- **additional_netrc_lines** (List of strings) - Optional - Default: `[]` - Additional lines prepended to the netrc file (used with `maven_install_json` only).
- **artifacts** (List of strings) - Optional - Default: `[]` - Maven artifact tuples in `artifactId:groupId:version` format.
- **boms** (List of strings) - Optional - Default: `[]` - Maven BOM tuples in `artifactId:groupId:version` format.
- **duplicate_version_warning** (String) - Optional - Default: `"warn"` - Controls behavior for duplicate artifacts: `"error"`, `"warn"`, or `"none"`.
- **excluded_artifacts** (List of strings) - Optional - Default: `[]` - Artifacts to exclude in `artifactId:groupId` format (only used on unpinned installs).
- **exclusions** (List of strings) - Optional - Default: `[]` - Maven artifact tuples in `artifactId:groupId` format to exclude.
- **fail_if_repin_required** (Boolean) - Optional - Default: `True` - Fail the build if Maven artifact inputs change but the lock file is not repinned.
- **fail_on_missing_checksum** (Boolean) - Optional - Default: `True` - Fail the build if checksums are missing.
- **fetch_javadoc** (Boolean) - Optional - Default: `False` - Fetch Javadoc for artifacts.
- **fetch_sources** (Boolean) - Optional - Default: `False` - Fetch sources for artifacts.
- **generate_compat_repositories** (Boolean) - Optional - Default: `False` - Generate repository aliases in a .bzl file for all JAR artifacts.
- **ignore_empty_files** (Boolean) - Optional - Default: `False` - Treat empty JAR files as not found.
- **index_file** (Label) - Optional - Default: `None` - File containing information for the Java Gazelle plugin.
- **known_contributing_modules** (List of strings) - Optional - Default: `[]` - List of Bzlmod modules known to contribute to this repository (only for the root module).
- **lock_file** (Label) - Optional - Default: `None` - Path to the lock file.
- **repin_instructions** (String) - Optional - Default: `""` - Instructions for repinning the repository if required.
- **repositories** (List of strings) - Optional - Default: `["https://repo1.maven.org/maven2"]` - List of artifact repositories.
- **resolve_timeout** (Integer) - Optional - Default: `600` - Timeout in seconds for dependency resolution.
- **resolver** (String) - Optional - Default: `"coursier"` - The dependency resolver to use (only for the root module).
- **strict_visibility** (Boolean) - Optional - Default: `False` - Controls visibility of transitive dependencies: `True` for private, `False` for public.
```
--------------------------------
### Configuring Maven Resolver with Unsafe Cache
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Example of configuring the Maven-backed resolver to use the local $HOME/.m2/repository for faster dependency resolution.
```bash
# Example environment variable setting (not a direct command)
export RJE_UNSAFE_CACHE=1
```
--------------------------------
### maven.install
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod-api.md
Installs Maven artifacts, potentially from a lock file.
```APIDOC
## maven.install
### Description
Installs Maven artifacts, potentially from a lock file.
### Method
Not applicable (Stardoc function)
### Endpoint
Not applicable
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
### Attributes
- **name** (Name) - Optional - Defaults to `"maven"`
- **aar_import_bzl_label** (Label) - Optional - Label to the `aar_import.bzl` file.
- **additional_coursier_options** (List of strings) - Optional - Defaults to `[]` - Additional options to pass to Coursier.
- **additional_netrc_lines** (List of strings) - Optional - Defaults to `[]` - Additional lines to add to the `.netrc` file.
- **artifacts** (List of strings) - Optional - Defaults to `[]` - List of Maven artifacts to install in `group:artifact:version` format.
- **boms** (List of strings) - Optional - Defaults to `[]` - List of Maven Bill of Materials (BOMs) to include.
- **duplicate_version_warning** (String) - Optional - Defaults to `""`
- **excluded_artifacts** (List of strings) - Optional - Defaults to `[]` - List of artifacts to exclude.
- **exclusions** (List of strings) - Optional - Defaults to `[]` - Maven artifact tuples, in `artifactId:groupId` format.
- **fail_if_repin_required** (Boolean) - Optional - Defaults to `false` - Fail the build if `repin` is required.
- **fail_on_missing_checksum** (Boolean) - Optional - Defaults to `false` - Fail the build if checksums are missing.
- **fetch_javadoc** (Boolean) - Optional - Defaults to `false` - Fetch Javadoc for the artifacts.
- **fetch_sources** (Boolean) - Optional - Defaults to `false` - Fetch sources for the artifacts.
- **generate_compat_repositories** (Boolean) - Optional - Defaults to `false` - Generate compatible repositories file.
- **ignore_empty_files** (Boolean) - Optional - Defaults to `false` - Ignore empty files during artifact processing.
- **index_file** (String) - Optional - Path to an index file for artifact resolution.
- **known_contributing_modules** (List of strings) - Optional - Defaults to `[]` - List of modules known to contribute to the build.
- **lock_file** (String) - Optional - Path to a lock file for dependency resolution.
- **repin_instructions** (String) - Optional - Instructions for repinning dependencies.
- **repositories** (List of strings) - Optional - Defaults to `[]` - List of Maven repositories to use.
- **resolve_timeout** (Integer) - Optional - Timeout in seconds for dependency resolution.
- **resolver** (String) - Optional - The resolver to use (e.g., `coursier`).
- **strict_visibility** (Boolean) - Optional - Defaults to `false` - Enforce strict visibility rules.
- **strict_visibility_value** (String) - Optional - Value for strict visibility.
- **use_credentials_from_home_netrc_file** (Boolean) - Optional - Defaults to `false` - Use credentials from the home `.netrc` file.
- **use_starlark_android_rules** (Boolean) - Optional - Defaults to `false` - Use Starlark rules for Android.
- **version_conflict_policy** (String) - Optional - Version conflict policy (e.g., `highest`, `lowest`).
```
--------------------------------
### Maven Install Configuration
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod-api.md
Configuration options for the `maven_install` rule, which manages external Maven dependencies.
```APIDOC
## `maven_install` Configuration Options
### Description
Configuration attributes for the `maven_install` rule.
### Parameters
#### Query Parameters
- **strict_visibility_value** (List of labels) - optional - Default: `["@rules_jvm_external//visibility:private"]`
- **use_credentials_from_home_netrc_file** (Boolean) - optional - Default: `False` - Whether to pass machine login credentials from the ~/.netrc file to coursier.
- **use_starlark_android_rules** (Boolean) - optional - Default: `False` - Whether to use the native or Starlark version of the Android rules.
- **version_conflict_policy** (String) - optional - Default: `"default"` - Policy for user-defined vs. transitive dependency version conflicts. If "pinned", choose the user-specified version in maven_install unconditionally. If "default", follow Coursier's default policy.
```
--------------------------------
### Specifying Artifacts with Detailed Information using maven.artifact
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Provides an example of using `maven.artifact` to specify an artifact with additional directives like exclusions. This is an alternative to simple Maven coordinate strings when more control is needed.
```python
maven.artifact(
group = "com.google.guava",
artifact = "guava",
version = "27.0-android",
exclusions = [
...
]
)
```
--------------------------------
### Install rules_jvm_external with bzlmod
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod.md
Add rules_jvm_external to your MODULE.bazel file and configure the maven extension for dependency management.
```Starlark
bazel_dep(name = "rules_jvm_external", version = "...")
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
artifacts = [
# This line is an example coordinate, you'd copy-paste your actual dependencies here
# from your build.gradle or pom.xml file.
"org.seleniumhq.selenium:selenium-java:4.4.0",
],
)
# You can split off individual artifacts to define artifact-specific options (this example sets `neverlink`).
# The `maven.install` and `maven.artifact` tags will be merged automatically.
maven.artifact(
artifact = "javapoet",
group = "com.squareup",
neverlink = True,
version = "1.11.1",
)
use_repo(maven, "maven")
```
--------------------------------
### Export Java Library Dependencies
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Reference downloaded JARs as Java library dependencies in your BUILD file using versionless labels. This example shows how to export JUnit.
```python
java_library(
name = "java_test_deps",
exports = [
"@maven//:junit_junit",
"@maven//:org_hamcrest_hamcrest_library",
],
)
```
--------------------------------
### Globally Excluding Artifacts with maven.install
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Illustrates how to exclude artifacts globally for a `maven.install` declaration using the `excluded_artifacts` attribute. This applies the exclusion to all dependencies resolved by that install declaration.
```python
maven.install(
artifacts = [
# ...
],
excluded_artifacts = [
"com.google.guava:guava",
],
)
```
--------------------------------
### Configure Maven Artifacts with Bzlmod
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Use this snippet in your MODULE.bazel file to declare rules_jvm_external as a dependency and configure artifact installation. It specifies artifacts to download and their repositories, with an option for a lock file.
```starlark
# MODULE.bazel
bazel_dep(name = "rules_jvm_external", version = "7.0.0")
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
artifacts = [
"junit:junit:4.12",
"androidx.test.espresso:espresso-core:3.1.1",
"org.hamcrest:hamcrest-library:1.3",
],
repositories = [
# Private repositories are supported through HTTP Basic auth
"http://username:password@localhost:8081/artifactory/my-repository",
"https://maven.google.com",
"https://repo1.maven.org/maven2",
],
lock_file = "//:maven_install.json",
)
```
--------------------------------
### Export Android Library Dependencies
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Reference downloaded JARs as Android library dependencies in your BUILD file using versionless labels. This example shows how to export Espresso core.
```python
android_library(
name = "android_test_deps",
exports = [
"@maven//:junit_junit",
"@maven//:androidx_test_espresso_espresso_core",
],
)
```
--------------------------------
### Example POM Dependency Nodes
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/examples/pom_file_generation/README.md
The generated XML file contains dependency nodes for the Java library's direct dependencies, including groupId, artifactId, and version.
```xml
com.google.guava
guava
27.1-jre
com.google.inject
guice
4.0
```
--------------------------------
### Example Kotlin Export Target
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Defines a kt_jvm_export target for publishing a Kotlin library to a Maven repository. This rule is analogous to java_export but is designed for Kotlin source code.
```python
# user_project/BUILD
load("@rules_jvm_external//:defs.bzl", "kt_jvm_export")
kt_jvm_export(
name = "exported_kt_lib",
maven_coordinates = "com.example:project-kt:0.0.1",
srcs = glob(["*.kt"]),
deps = [
"//user_project/utils",
"@maven//:org_jetbrains_kotlin_kotlin_stdlib",
],
)
```
--------------------------------
### Example Java Export Target
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Defines a java_export target for publishing a Java library to a Maven repository. Specify maven coordinates and optionally a POM template. Dependencies can include other local targets or external Maven artifacts.
```python
# user_project/BUILD
load("@rules_jvm_external//:defs.bzl", "java_export")
java_export(
name = "exported_lib",
maven_coordinates = "com.example:project:0.0.1",
pom_template = "pom.tmpl", # You can omit this
srcs = glob(["*.java"]),
deps = [
"//user_project/utils",
"@maven//:com_google_guava_guava",
],
)
```
--------------------------------
### Build Scala Application
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/examples/scala_akka/README.md
Use this command to build the Scala application.
```bash
bazel build app
```
--------------------------------
### maven_install Parameters
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/api.md
Configuration options for the `maven_install` rule.
```APIDOC
## maven_install Parameters
### Description
Configuration options for the `maven_install` rule.
### Parameters
#### Query Parameters
- **strict_visibility_value** (string array) - Optional - Allows changing transitive dependencies strict visibility scope from private to specified scopes list. Default: `["//visibility:private"]`
- **resolve_timeout** (long) - Optional - The execution timeout of resolving and fetching artifacts. Default: `600`
- **additional_netrc_lines** (string array) - Optional - Additional lines prepended to the netrc file used by `http_file` (with `maven_install_json` only). Default: `[]`
- **use_credentials_from_home_netrc_file** (boolean) - Optional - Whether to pass machine login credentials from the ~/.netrc file to coursier. Default: `False`
- **fail_if_repin_required** (boolean) - Optional - Whether to fail the build if the required maven artifacts have been changed but not repinned. Requires the `maven_install_json` to have been set. Default: `True`
- **use_starlark_android_rules** (boolean) - Optional - Whether to use the native or Starlark version of the Android rules. Default is False if the running version of Bazel supports native aar_import. If the running version of Bazel does not support native aar_import, this parameter is ignored and the Starlark Android rules is used. Default: `False`
- **aar_import_bzl_label** (string) - Optional - The label (as a string) to use to import aar_import from. This is usually needed only if the top-level workspace file does not use the typical default repository name to import the Android Starlark rules. Default is "@rules_android//rules:rules.bzl". Default: `"@rules_android//rules:rules.bzl"`
- **duplicate_version_warning** (string) - Optional - What to do if an artifact is specified multiple times. If "error" then fail the build, if "warn" then print a message and continue, if "none" then do nothing. Default is "warn". Default: `"warn"`
- **repin_instructions** (string) - Optional - Instructions to re-pin dependencies in your repository. Will be shown when re-pinning is required. Default: `None`
- **ignore_empty_files** (boolean) - Optional - Treat jars that are empty as if they were not found. Default: `False`
- **additional_coursier_options** (string array) - Optional - Additional options that will be passed to coursier. Default: `[]`
```
--------------------------------
### maven_install Macro
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/api.md
The maven_install macro resolves and fetches artifacts transitively from Maven repositories.
```APIDOC
## maven_install
### Description
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.
### Method
`load`
### Endpoint
`@rules_jvm_external//:defs.bzl`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Parameters
- **name** (string) - Optional - A unique name for this Bazel external repository. Defaults to `"maven"`.
- **repositories** (list of strings) - Optional - A list of Maven repository URLs, specified in lookup order. Supports URLs with HTTP Basic Authentication, e.g. "https://username:password@example.com". Defaults to `[]`.
- **artifacts** (list of strings) - Optional - A list of Maven artifact coordinates in the form of `group:artifact:version`. Defaults to `[]`.
- **boms** (list of strings) - Optional - A list of Maven artifact coordinates in the form of `group:artifact:version` which refer to Maven BOMs. Defaults to `[]`.
- **resolver** (string) - Optional - Which resolver to use. One of `coursier`, `gradle` or `maven`. Defaults to `"coursier"`.
- **fail_on_missing_checksum** (boolean) - Optional - Fail the fetch if checksum attributes are not present. Defaults to `True`.
- **fetch_sources** (boolean) - Optional - Additionally fetch source JARs. Defaults to `False`.
- **fetch_javadoc** (boolean) - Optional - Additionally fetch javadoc JARs. Defaults to `False`.
- **excluded_artifacts** (list of strings) - Optional - A list of Maven artifact coordinates in the form of `group:artifact` to be excluded from the transitive dependencies. Defaults to `[]`.
- **generate_compat_repositories** (boolean) - Optional - Additionally 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`. Defaults to `False`.
- **version_conflict_policy** (string) - Optional - Policy for user-defined vs. transitive dependency version conflicts. If "pinned", choose the user's version unconditionally. If "default", follow Coursier's default policy. Defaults to `"default"`.
- **maven_install_json** (label) - Optional - A label to a `maven_install.json` file to use pinned artifacts for generating build targets. e.g `//:maven_install.json`. Defaults to `None`.
- **override_targets** (dict) - Optional - A 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. Defaults to `{}`.
- **strict_visibility** (boolean) - Optional - Controls 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. Defaults to `False`.
- **strict_visibility_value** (any) - Optional - Description not provided. Defaults to unspecified.
- **resolve_timeout** (int) - Optional - Description not provided. Defaults to unspecified.
- **additional_netrc_lines** (list of strings) - Optional - Description not provided. Defaults to unspecified.
- **use_credentials_from_home_netrc_file** (boolean) - Optional - Description not provided. Defaults to unspecified.
- **fail_if_repin_required** (boolean) - Optional - Description not provided. Defaults to unspecified.
- **use_starlark_android_rules** (boolean) - Optional - Description not provided. Defaults to unspecified.
- **aar_import_bzl_label** (label) - Optional - Description not provided. Defaults to unspecified.
- **duplicate_version_warning** (boolean) - Optional - Description not provided. Defaults to unspecified.
- **repin_instructions** (string) - Optional - Description not provided. Defaults to unspecified.
- **ignore_empty_files** (boolean) - Optional - Description not provided. Defaults to unspecified.
- **additional_coursier_options** (list of strings) - Optional - Description not provided. Defaults to unspecified.
### Request Example
```python
load("@rules_jvm_external//:defs.bzl", "maven_install")
maven_install(
name = "my_maven_repo",
artifacts = [
"com.google.guava:guava:31.1-jre",
"org.apache.logging.log4j:log4j-api:2.17.1",
],
repositories = [
"https://repo1.maven.org/maven2/",
"https://jitpack.io",
],
version_conflict_policy = "pinned",
)
```
### Response
#### Success Response (200)
This macro does not directly return a response in the traditional HTTP sense. It configures Bazel's external repository system.
#### Response Example
N/A
```
--------------------------------
### Load Basic Functions in BUILD File
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/includes/main_functions_header.md
Load the maven_install and artifact functions at the top of your BUILD file to use them.
```python
load("@rules_jvm_external//:defs.bzl", "maven_install", "artifact")
```
--------------------------------
### Fetch source JARs with maven_install
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Set `fetch_sources = True` in your `maven_install` rule to download source JARs alongside the main artifact JARs.
```python
maven_install(
artifacts = [
# ...
],
repositories = [
# ...
],
fetch_sources = True,
)
```
--------------------------------
### Loading the maven struct
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/api.md
Instructions on how to load the `maven` struct for use in BUILD files.
```APIDOC
## Loading the maven struct
### Description
To use these functions, load the `maven` struct at the top of your BUILD file.
### Code Example
```python
load(@rules_jvm_external//:specs.bzl, "maven")
```
```
--------------------------------
### Default Version Conflict Resolution
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Demonstrates the default behavior where transitive dependencies resolve to the highest version. This example shows Guava resolving to 26.0-android when pulled transitively.
```starlark
maven.install(
name = "pinning",
artifacts = [
"com.google.cloud:google-cloud-storage:1.66.0",
],
)
```
```shell
$ bazel query @pinning//:all | grep guava_guava
@pinning//:com_google_guava_guava
@pinning//:com_google_guava_guava_26_0_android
```
--------------------------------
### Run Scala Application
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/examples/scala_akka/README.md
Use this command to run the Scala application.
```bash
bazel run app
```
--------------------------------
### Generated targets for junit:junit
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Example of targets generated by `rules_jvm_external` for the `junit:junit` artifact, as seen via `bazel query`. These include `alias` and `jvm_import` rules.
```python
alias(
name = "junit_junit_4_12",
actual = "@maven//:junit_junit",
)
jvm_import(
name = "junit_junit",
jars = ["@maven//:https/repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar"],
srcjar = "@maven//:https/repo1.maven.org/maven2/junit/junit/4.12/junit-4.12-sources.jar",
deps = ["@maven//:org_hamcrest_hamcrest_core"],
tags = ["maven_coordinates=junit:junit:4.12"],
)
jvm_import(
name = "org_hamcrest_hamcrest_core",
jars = ["@maven//:https/repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"],
srcjar = "@maven//:https/repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar",
deps = [],
tags = ["maven_coordinates=org.hamcrest:hamcrest.library:1.3"],
)
```
--------------------------------
### Multiple maven_install.json Files
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
When using multiple `maven.install` declarations, each must have a unique `name` and its own distinct `lock_file` to manage different sets of dependencies separately.
```starlark
maven.install(
name = "foo",
lock_file = "//:foo_maven_install.json",
# ...
)
maven.install(
name = "bar",
lock_file = "//:bar_maven_install.json",
# ...
)
```
--------------------------------
### Build Spring Boot Application with Bazel
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/examples/spring_boot/README.md
Use this command to build the Spring Boot application. Ensure your Bazel workspace is correctly configured.
```bash
bazel build //src/main/java/hello:app
```
--------------------------------
### Install Maven dependencies with BOM support
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Use the `boms` attribute to specify Maven Bill of Materials (BOM) files for dependency management. This allows omitting version numbers for artifacts included in the BOM.
```starlark
maven.install(
boms = [
"org.seleniumhq.selenium:selenium-bom:4.18.1",
],
artifacts = [
# This dependency is included in the `selenium-bom`, so we can omit the version number
"org.seleniumhq.selenium:selenium-java",
],
)
```
--------------------------------
### Run All Tests
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Execute all tests within the project using Bazel.
```bash
$ bazel test //...
```
--------------------------------
### Forcing a Specific Dependency Version
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Shows how to use `force_version` to ensure a specific version of an artifact is used, even if it conflicts with other dependencies or default resolution strategies. This example forces Guava version 23.3-jre.
```starlark
maven.install(
name = "forcing_versions",
artifacts = [
# And something that depends on a more recent version of guava
"xyz.rogfam:littleproxy:2.1.0",
],
)
# Specify an ancient version of guava, and force its use. If we try to use `[23.3-jre]` as the version,
# the resolution will fail when using `coursier`
maven.artifact(
artifact = "guava",
force_version = "true",
group = "com.google.guava",
version = "23.3-jre",
)
```
--------------------------------
### Run Scala Tests
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/examples/scala_akka/README.md
Use this command to run the tests for the Scala application.
```bash
bazel test test
```
--------------------------------
### Custom Location for maven_install.json
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Specify a custom path for `maven_install.json` by setting the `lock_file` attribute to a different file label. Ensure a BUILD file exists in the specified directory if needed.
```starlark
maven.install(
name = "maven_install_in_custom_location",
artifacts = ["com.google.guava:guava:27.0-jre"],
repositories = ["https://repo1.maven.org/maven2"],
lock_file = "//tests/custom_maven_install:maven_install.json",
)
```
--------------------------------
### Import Gradle version catalog with from_toml
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod.md
Use the `from_toml` tag to import dependencies declared in a Gradle version catalog file.
```Starlark
maven.from_toml(
libs_versions_toml = "//gradle:libs.versions.toml",
)
```
--------------------------------
### Creating a Release Archive
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/RELEASING.md
Generate a gzipped tar archive of the release using git archive. Replace ${TAG} with the actual release version number.
```shell
git archive --format=tar --prefix=rules_jvm_external-${TAG}/ ${TAG} | gzip > rules_jvm_external-{TAG}.tar.gz
```
--------------------------------
### Multiple maven_install Declarations for Version Isolation
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Shows how to declare multiple `maven.install` targets with unique repository names to manage different versions of the same artifact independently. This is useful for projects with components requiring distinct dependency trees.
```starlark
maven.install(
name = "server_app",
artifacts = [
"com.google.guava:guava:27.0-jre",
],
)
maven.install(
name = "android_app",
artifacts = [
"com.google.guava:guava:27.0-android",
],
)
```
--------------------------------
### Configure maven_install with Lock File
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Specify the `lock_file` attribute in your `maven.install` rule in `MODULE.bazel` to point to your `maven_install.json`. This enables artifact pinning and integration with Bazel's downloader.
```starlark
maven.install(
# artifacts, repositories, ...
lock_file = "//:maven_install.json",
)
```
--------------------------------
### Run Robolectric Test with Bazel
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/examples/kt_android_local_test/README.md
Use this command to execute Robolectric tests in your Bazel workspace. Ensure your BUILD file is configured correctly for Robolectric dependencies.
```bash
bazel test //src/test:main_activity_test
```
--------------------------------
### Publishing Artifact to Google Cloud Storage
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Command to publish the artifact to a Google Cloud Storage bucket.
```bash
bazel run --define "maven_repo=gs://example-bucket/repository" //user_project:exported_lib.publish
```
--------------------------------
### Referencing Isolated Artifacts in BUILD Files
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Illustrates how to reference artifacts managed by separate `maven.install` declarations in BUILD files using versionless aliases. The alias points to the specific versioned artifact within the named repository.
```python
java_binary(
name = "my_server_app",
srcs = ...
deps = [
# a versionless alias to @server_app//:com_google_guava_guava_27_0_jre
"@server_app//:com_google_guava_guava",
]
)
android_binary(
name = "my_android_app",
srcs = ...
deps = [
# a versionless alias to @android_app//:com_google_guava_guava_27_0_android
"@android_app//:com_google_guava_guava",
]
)
```
--------------------------------
### Run Spring Boot Application with Bazel
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/examples/spring_boot/README.md
Execute this command to run the Spring Boot application directly from Bazel. This is useful for development and testing.
```bash
bazel run //src/main/java/hello:app
```
--------------------------------
### Adding a Module to Bazel Central Registry
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/RELEASING.md
Run this Bazel command to initiate the process of adding or updating a module in the Bazel Central Registry. It will prompt for necessary details like module name, version, and source archive URL.
```shell
bazel run //tools:add_module
```
--------------------------------
### Build POM Dependency Nodes
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/examples/pom_file_generation/README.md
Build the specified Bazel target to generate the POM file with dependency nodes. This command initiates the process of creating the XML output.
```bash
bazel build //:my_library_pom
```
--------------------------------
### Update maven_install.json
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
When changes are made to artifacts or repositories, run this command to re-pin the `@maven` repository and update `maven_install.json`. Without this, `maven_install` will not recognize changes made in `MODULE.bazel`.
```bash
$ REPIN=1 bazel run @maven//:pin
```
--------------------------------
### Configure Maven Artifact Resolution with maven_install
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/api.md
Use this macro to set up Bazel to resolve and fetch Java artifacts from Maven repositories. It supports various configurations for repositories, artifacts, and dependency management.
```bazel
load("@rules_jvm_external//:defs.bzl", "maven_install")
maven_install(
name = "maven",
repositories = [
"https://repo1.maven.org/maven2",
],
artifacts = [
"com.google.guava:guava:30.1-jre",
],
boms = [
"com.example:my-bom:1.0.0",
],
resolver = "coursier",
fail_on_missing_checksum = True,
fetch_sources = False,
fetch_javadoc = False,
excluded_artifacts = [
"org.apache.logging.log4j:log4j-core",
],
generate_compat_repositories = False,
version_conflict_policy = "default",
maven_install_json = "//:maven_install.json",
override_targets = {
"com.example:some-artifact": "//:override_target",
},
strict_visibility = False,
resolve_timeout = 60,
additional_netrc_lines = [],
use_credentials_from_home_netrc_file = False,
fail_if_repin_required = False,
use_starlark_android_rules = False,
aar_import_bzl_label = "@rules_jvm_external//:aar_import.bzl",
duplicate_version_warning = True,
repin_instructions = "//:repin_instructions.txt",
ignore_empty_files = False,
additional_coursier_options = [],
)
```
--------------------------------
### Check for outdated artifacts
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Run this command to list all dependencies that may require an update in your Bazel workspace.
```bash
$ bazel run @maven//:outdated
```
--------------------------------
### Publishing Artifact to Sonatype OSS Repository
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Command to publish the artifact to Sonatype's OSS repository, including credentials and GPG signing.
```bash
MAVEN_USER=example_user MAVEN_PASSWORD=hunter2 bazel run --stamp \
--define "maven_repo=https://oss.sonatype.org/service/local/staging/deploy/maven2" \
--define gpg_sign=true \
//user_project:exported_lib.publish
```
--------------------------------
### Load Maven Specification Functions
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/includes/spec_functions_header.md
Load the `maven` struct to access helper functions for specifying Maven artifacts and repositories. This must be done at the top of your BUILD file.
```python
load("@rules_jvm_external//:specs.bzl", "maven")
```
--------------------------------
### Using java_plugin_artifact for Annotation Processors
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Demonstrates how to use the `java_plugin_artifact` macro to specify an annotation processor for a `java_library` target. Ensure the artifact is declared in a `maven_install`.
```python
java_library(
name = "some_lib",
srcs = ["SrcUsingAuto.java"],
plugins = [
java_plugin_artifact("com.google.auto.value:auto-value", "com.google.auto.value.processor.AutoValueProcessor"),
],
)
```
--------------------------------
### Load artifact helper macro
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Include this load statement at the top of your BUILD file to use the `artifact` helper macro for referencing versionless targets.
```python
load("@rules_jvm_external//:defs.bzl", "artifact")
```
--------------------------------
### Run Tests for Spring Boot Application with Bazel
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/examples/spring_boot/README.md
This command runs all tests associated with the Spring Boot application. It's essential for verifying application correctness.
```bash
bazel test //src/test/...
```
--------------------------------
### Ignore Empty JAR Files
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Configures the build to ignore empty JAR files, preventing them from being included in the dependency tree.
```starlark
maven.install(
artifacts = [
# ...
],
repositories = [
# ...
],
# ...
ignore_empty_files = True
)
```
--------------------------------
### Publishing Artifact to Local Maven Repository
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Command to publish the artifact to a local Maven repository using Bazel.
```bash
bazel run --define "maven_repo=file://$HOME/.m2/repository" //user_project:exported_lib.publish
```
--------------------------------
### Publishing Artifact to Amazon S3 Bucket
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Command to publish the artifact to an Amazon S3 bucket.
```bash
bazel run --define "maven_repo=s3://example-bucket/repository" //user_project:exported_lib.publish
```
--------------------------------
### Disable failing on missing checksums
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Configure `maven_install` with `fail_on_missing_checksum = False` to prevent artifact resolution failures when checksum files are missing.
```python
maven_install(
artifacts = [
# ...
],
repositories = [
# ...
],
fail_on_missing_checksum = False,
)
```
--------------------------------
### Set JVM Options for Artifact Resolver
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Provides JVM options to the artifact resolver via the `JDK_JAVA_OPTIONS` environment variable in `.bazelrc`.
```bash
build --repo_env=JDK_JAVA_OPTIONS=-Djavax.net.ssl.trustStore=
```
--------------------------------
### Import from TOML
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod-api.md
Imports dependencies from a Gradle format `libs.versions.toml` file, allowing for centralized dependency management.
```APIDOC
## from_toml
### Description
Allows a project to import dependencies from a Gradle format `libs.versions.toml` file.
### Attributes
#### Path Parameters
- **name** (Name) - Optional - Default: `"maven"`
- **bom_modules** (List of strings) - Optional - Description: List of modules in `group:artifact` format to treat as BOMs, not artifacts. Default: `[]`
- **libs_versions_toml** (Label) - Required - Description: Gradle `libs.versions.toml` file to use.
```
--------------------------------
### View Generated POM Dependencies
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/examples/pom_file_generation/README.md
Display the content of the generated POM file to inspect the dependency nodes. This command allows verification of the output from the build process.
```bash
cat bazel-bin/my_library_pom.xml
```
--------------------------------
### maven.from_toml
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod-api.md
Creates Maven artifacts from a TOML file.
```APIDOC
## maven.from_toml
### Description
Creates Maven artifacts from a TOML file.
### Method
Not applicable (Stardoc function)
### Endpoint
Not applicable
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
### Attributes
- **name** (Name) - Optional - Defaults to `"maven"`
- **bom_modules** (List of strings) - Optional - Defaults to `[]` - List of TOML modules to include from the BOM.
- **libs_versions_toml** (String) - Required - Label to the `libs_versions.toml` file.
```
--------------------------------
### Declare BOMs from external files using bom_modules
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod.md
Specify external BOM modules to be used with the `from_toml` tag by providing a list of gradle modules to the `bom_modules` attribute.
```Starlark
maven.from_toml(
libs_versions_toml = "//gradle:libs.versions.toml",
bom_modules = [
"com.google.guava:guava-bom",
],
)
```
--------------------------------
### Publishing Artifact to GCP Artifact Registry
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Command to publish the artifact to a GCP Artifact Registry.
```bash
bazel run --define "maven_repo=artifactregistry://us-west1-maven.pkg.dev/project/repository" //user_project:exported_lib.publish
```
--------------------------------
### Tagging a Release in Git
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/RELEASING.md
Use these commands to switch to the master branch, pull the latest changes, tag the release with a major.minor version, and push the tag to the remote repository.
```shell
git switch master
git pull
git tag XX.YY
git push --tags
```
--------------------------------
### Use custom Coursier download URL
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/README.md
Specify a custom URL for downloading Coursier using the `COURSIER_URL` environment variable. This is useful if default URLs are inaccessible.
```bash
$ bazel build @maven_with_unsafe_shared_cache//... --repo_env=COURSIER_URL='https://my_secret_host.com/vXYZ/coursier.jar'
```
--------------------------------
### Extended Gradle version catalog fields
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod.md
Demonstrates additional fields supported by rules_jvm_external for library entries in a Gradle version catalog, such as classifier, exclusions, force_version, is_bom, and package.
```toml
[libraries]
guavaBom = { module = "com.google.guava:guava-bom", version = "33.4.8-jre", is_bom = "true" }
guava = { module = "com.google.guava:guava" }
clickhouse = { module = "com.clickhouse:clickhouse-jdbc", version = "0.9.2", classifier = "all", force_version = "true" }
misk = { module = "com.squareup.misk:misk-core", version = "1.0.0", exclusions = "['com.example:unwanted']" }
```
--------------------------------
### Update MODULE.bazel with lock file
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod.md
Add the `lock_file` attribute to the `maven.install()` call to reference the generated JSON lockfile.
```Starlark
maven.install(
...
lock_file = "//:maven_install.json",
)
```
--------------------------------
### Generate Javadoc
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/api.md
Use the javadoc rule to generate API documentation for Java libraries. Specify the libraries to document via the 'deps' attribute. Transitive dependencies are not currently documented.
```python
javadoc(
name = "my_javadoc",
deps = [
":my_library",
"//:another_library",
],
)
```
--------------------------------
### Pin dependencies using @maven//:pin
Source: https://github.com/bazel-contrib/rules_jvm_external/blob/master/docs/bzlmod.md
Run the bazel target to generate a JSON lockfile for transitive dependencies.
```sh
$ bazel run @maven//:pin
```