Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usage guidance to README.md #7

Merged
merged 4 commits into from
Feb 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,51 @@
# bazel_jar_jar
JarJar rules for bazel (rename packages and classes in existing jars)

JarJar rules for [Bazel](https://bazel.build/) (rename packages and classes in existing jars)

This rule uses [pantsbuild's jarjar fork](https://github.com/pantsbuild/jarjar).
The main use case is to use more than one version of a jar at a time with different versions mapped to
a different package.
The main use case is to use more than one version of a jar at a time with different versions mapped to a different package. It can also be used to do [*dependency shading*](https://softwareengineering.stackexchange.com/questions/297276/what-is-a-shaded-java-dependency).


## How to add to Bazel `WORKSPACE`

```
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "com_github_johnynek_bazel_jar_jar",
commit = "16e48f319048e090a2fe7fd39a794312d191fc6f", # Latest commit SHA as at 2019/02/13
remote = "git://github.com/johnynek/bazel_jar_jar.git",
)

load(
"@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl",
"jar_jar_repositories",
)
jar_jar_repositories()
```


## Usage

_Note_: Example code exists in [`test/example`](/test/example)

Specify a rule in a file that will remap one package path into another:

```
rule com.twitter.scalding.** foo.@1
```

Put that file in the same directory as the Bazel `BUILD` file that will specify the `jar_jar` rules. Reference that file in the `rules` field of the `jar_jar` rule.

```
jar_jar(
name = "shaded_args",
input_jar = "@com_twitter_scalding_args//jar",
rules = "<FILENAME>"
)
```

The `input_jar` specifies the package that will be relocated. `name` is the target label to be used in place of the original package target label.


As an example, see the test/example.
Change any references in your code from the original package path to the new shaded package path. For example: `import com.twitter.scalding.Args` becomes `import foo.Args`.