Bazel uses a flat dependency model that does not support transitive dependencies. It is an error to attempt to redefine an external workspace.
This repository provides the following:
-
A
requirerule that will check if an existing rule exists before attempting to redefine it. -
A tool to generate
requiretemplates from gradle.
| Name | Description | | -------------------: | -----------: | --------: | -------- | | require_repositories | Load dependencies for this repo. | | require | Require a single dependency. |
git_repository(
name = "org_pubref_rules_require",
remote = "https://github.com/pubref/rules_require",
tag = "v0.1.0",
)
load("@org_pubref_rules_require//require:rules.bzl", "require_repositories")
require_repositories()The convention is to have one minimal build.gradle file per
subdirectory in third_party. For example, consider the following
example build.gradle file in third_party/aether:
third_party/aether/
└── build.gradleapply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.eclipse.aether', name: 'aether-spi', version: '1.1.0'
...
}The following gendeps tool invocation will invoke gradle, collect
the dependency tree, and generate three files in the same directory as
the build.gradle source file:
$ bazel build @org_pubref_rules_require//java/org/pubref/tools/gradle:gendeps_deploy.jar \
&& java -jar ./bazel-bin/external/org_pubref_rules_require/java/org/pubref/tools/gradle/gendeps_deploy.jar \
-g third_party/aether/build.gradlethird_party/aether/
├── build.gradle
├── BUILD (1)
├── README.md (2)
└── requires.bzl (3)-
The generated
require.bzlcontains a macro defintion thatrequire's all the dependencies for a given gradle configuration. The common ones arecompile,runtime,testCompile, andtestRuntime. This file should be loaded within yourWORKSPACE(see below). -
The generated
BUILDcontains ajava_libraryrule that exports all the dependencies for a given gradle configuration. -
The generated
README.mdcontains a human-readable summary of the dependencies.
Invoke a generated configuration from your WORKSPACE. You can alias
the name of the function to something more specific if needed to avoid
name collisions:
load("//third_party/aether:requires.bzl", aether_runtime = "runtime")
aether_runtime()- examples/aether/build.gradle (source file).
- examples/aether/Makefile (convenience).
- examples/aether/BUILD (generated file).
- examples/aether/requires.bzl (generated file).
- examples/aether/README.md (generated file).
Contributions welcome; please create Issues or GitHub pull requests.