A turn-key template repository to develop Java code using Bazel, with prepopulated common dependencies.
# Run the test, which first builds exatly everything needed
$ bazel test //src/test/java/foo:FooTest
# Or just build
$ bazel build //src/main/java/foo:Foo
This compiles ./Foo.java
using the java_library
defined in ./BUILD
.
Assuming you're in the root of this repository,
ROOT=$(pwd)
wget https://github.com/johnynek/bazel-deps/archive/master.zip
unzip master.zip
pushd bazel-deps-master
bazel build //src/scala/com/github/johnynek/bazel_deps:parseproject_deploy.jar # should take around 1 minute
./gen_maven_deps.sh generate -r "$ROOT" -d maven_deps.yaml -s thirdparty/workspace.bzl
popd
Suppose you want to use org.reactivestreams:reactive-streams:jar:1.0.1
.
Add the following to the end of maven_deps.yaml
(indentation is important):
org.reactivestreams:
reactive-streams:
version: "1.0.1"
lang: java
Then follow the instructions in "Created using", above.
After running, you should see a new file named thirdparty/jvm/org/reactivestreams/BUILD
.
- "thirdparty" should be named "third_party", which is blocked on bazelbuild/bazel#3639
- We shouldn't use
bind()
- instead, we should reference the maven jars directly. We actually don't even need ajava_library
in thirdparty/ - we can usejava_import
directly on the jars we get frommaven_jar
. - Configuring annotation prcessors is manual (bazeltools/bazel-deps#62)
- Test-only dependencies (such as //thirdparty/jvm/junit:junit) should be marked have
testonly = 1
, lest they mistakenly end up in production code.