Skip to content

pubref/rules_require

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rules_require Build Status

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:

  1. A require rule that will check if an existing rule exists before attempting to redefine it.

  2. A tool to generate require templates from gradle.

Rules

| Name | Description | | -------------------: | -----------: | --------: | -------- | | require_repositories | Load dependencies for this repo. | | require | Require a single dependency. |

Usage

1. Add rules_require your WORKSPACE

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

2. Generate dependencies from gradle.

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.gradle
apply 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.gradle
third_party/aether/
├── build.gradle
├── BUILD (1)
├── README.md (2)
└── requires.bzl (3)
  1. The generated require.bzl contains a macro defintion that require's all the dependencies for a given gradle configuration. The common ones are compile, runtime, testCompile, and testRuntime. This file should be loaded within your WORKSPACE (see below).

  2. The generated BUILD contains a java_library rule that exports all the dependencies for a given gradle configuration.

  3. The generated README.md contains a human-readable summary of the dependencies.

3. Load the generated requires.bzl in your WORKSPACE.

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

Example

  1. examples/aether/build.gradle (source file).
  2. examples/aether/Makefile (convenience).
  3. examples/aether/BUILD (generated file).
  4. examples/aether/requires.bzl (generated file).
  5. examples/aether/README.md (generated file).

Contributing

Contributions welcome; please create Issues or GitHub pull requests.

About

Dependency management utilities for Bazel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published