blob: 623b424ae7648ea9c382c3a984788f26b7b34211 [file] [log] [blame] [view]
cushon58dc6b92017-07-06 17:04:27 -04001---
2layout: posts
3title: Configuring your Java builds
4---
5
6Let say that you want to build for Java 8 and Error Prone checks off but keep
7the tools directory provided with Bazel in the package path, you could do that
8by having the following rc file:
9
10```
11build --javacopt=-XepDisableAllChecks
12build --javacopt="-source 8 -target 8"
13```
14
15However, the file would becomes quickly overloaded, especially if you take
16all languages and options into account. Instead, you can tweak the
17[java_toolchain](https://github.com/bazelbuild/bazel/tree/0e1680e58f01f3d443f7e68865b5a56b76c9dadf/tools/jdk/BUILD#L73)
18rule that specifies the various options for the java compiler. So in a
19BUILD file:
20
21```python
22java_toolchain(
23 name = "my_toolchain",
24 encoding = "UTF-8",
25 source_version = "8",
26 target_version = "8",
27 misc = [
Googler24e14092018-05-04 16:06:27 -070028 "-Xep:CollectionIncompatibleType:ERROR", # https://errorprone.info/bugpattern/CollectionIncompatibleType
cushon58dc6b92017-07-06 17:04:27 -040029 ],
30)
31```
32
33And to keep it out of the tools directory (or you need to copy the rest
34of the package), you can redirect the default one in a bazelrc:
35
36```
37build --java_toolchain=//package:my_toolchain
38```
39
40In the future, toolchain rules should be the configuration points for all
41the languages but it is a long road. We also want to make it easier to
42rebind the toolchain using the `bind` rule in the WORKSPACE file.
43