Follow these slides both to learn about Bazel and to get more context on the exercises.
You should have installed:
- Bazel (optionally Bazelisk)
- Java JDK (e.g.
sudo apt install openjdk-11-jdk). Note: Tested with JDK 11, and at least JDK 19 has issues under MacOS. java -versionshould work
Let's execute a Java binary.
- Edit:
java/src/main/java/bazel/bootcamp/BUILD - Add a
java_binarytarget for theHelloBazelBootcamp.javafile - Run the binary using
bazel run //java/src/main/java/bazel/bootcamp:HelloBazelBootcamp
Let's compile and run the server code.
- The Go
BUILDfiles can be fully generated by Gazelle. Run gazelle withbazel run //:gazelle - Run the go binary using
bazel run //go/cmd/server - Go to http://localhost:8081 to see results (there won't be any logs yet):
curl http://localhost:8081
Now let's compile and run the client code. It uses GRPC so we'll need to build the proto files and link them as dependencies.
- Edit the
BUILDfile forlogger.protojava_proto_librarydocumentationjava_grpc_librarydocumentation (look towards the bottom of the page for Bazel related documentation)
- Edit the
BUILDfile forJavaLoggingClientLibrary.java - Edit the
BUILDfile forJavaLoggingClient.java bazel runthe Java binary you wrotebazel runthe Go binary from Section 2- Send messages from the client to the server and view them on http://localhost:8081
Let's make Bazel also run the java unit tests.
- Edit the
BUILDfile forJavaLoggingClientLibraryTest.javaHint
Names matter for tests. Thejava_testfor this file should be namedJavaLoggingClientLibraryTest - Edit the
BUILDfile forJavaLoggingClientTest.java - Run the tests using
bazel test
There is an integration test that uses both the go server binary, and the java client binary. Let's run it through Bazel.
- Edit the
BUILDfile forintegrationtest.sh - Run the test using
bazel testand make sure that it passes - Now run the test using
bazel test <target> --runs_per_test=10. It will fail, so you might need to find how to fix it.Hint
You may need to modify theBUILDfile again to make this workHint
Maybe because of the nature of the test you can't run it concurrently, and needs to be run sequentially?
The slides contain some examples you can try by yourself.
You can also use as reference the Official query guide.