Skip to content

AlexTereshenkov/java-bazel-build-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimal Bazel project showing how to build a Java project with external Maven dependencies.

Query

Show all Maven dependencies available in the repository

bazel query "@maven//:*"

Show all targets in the project

$ bazel query //...

Build

Build the main binary

$ bazel build //src/main/java/com/example:main
$ bazel-bin/src/main/java/com/example/main

Build all targets

$ bazel build //...

Test

Run all tests

$ bazel test //...

Run tests without using the cache:

$ bazel test --cache_test_results=no //...

Coverage

Record test coverage. Disable remote execution if the toolchain used doesn't provide the tools e.g. GCov.

$ apt install lcov
$ bazel coverage --nocache_test_results --strategy=CoverageReport=local //...
$ genhtml --output genhtml <path-to-the-coverage.data-file>

Use different Java version

https://bazel.build/docs/user-manual#java_runtime_version

build --java_language_version=17
build --java_runtime_version=remotejdk_17

Readings

About

An example Java project built with Bazel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published