diff options
Diffstat (limited to 'site/blog')
-rw-r--r-- | site/blog/_posts/2015-06-25-ErrorProne.md | 17 | ||||
-rw-r--r-- | site/blog/_posts/2015-07-08-Java-Configuration.md | 43 |
2 files changed, 60 insertions, 0 deletions
diff --git a/site/blog/_posts/2015-06-25-ErrorProne.md b/site/blog/_posts/2015-06-25-ErrorProne.md new file mode 100644 index 0000000000..d79d87accb --- /dev/null +++ b/site/blog/_posts/2015-06-25-ErrorProne.md @@ -0,0 +1,17 @@ +--- +layout: posts +title: Checking your Java errors with Error Prone. +--- + +We recently open-sourced our support for [Error Prone](http://errorprone.info). +[Error Prone](http://errorprone.info) checks for common mistakes in Java code +that will not be caught by the compiler. + +We turned [Error Prone](http://errorprone.info) on by default but you can easily +turn it off by using the Javac option `-XepDisableAllChecks`. To do so, simply +specify `--javacopt='XepDisableAllChecks` to the list of Bazel's options. You +can also tune the checks error-prone will perform by using the [`-Xep:` +flags](http://errorprone.info/docs/flags). + +See the [documentation of Error Prone](http://errorprone.info/docs/installation) for more +on Error Prone. diff --git a/site/blog/_posts/2015-07-08-Java-Configuration.md b/site/blog/_posts/2015-07-08-Java-Configuration.md new file mode 100644 index 0000000000..2d0a3c70c5 --- /dev/null +++ b/site/blog/_posts/2015-07-08-Java-Configuration.md @@ -0,0 +1,43 @@ +--- +layout: posts +title: Configuring your Java builds +--- + +Let say that you want to build for Java 8 and Error Prone checks off but keep +the tools directory provided with Bazel in the package path, you could do that +by having the following rc file: + +``` +build --javacopt=-XepDisableAllChecks +build --javacopt="-source 8 -target 8" +``` + +However, the file would becomes quickly overloaded, especially if you take +all languages and options into account. Instead, you can tweak the +[java_toolchain](https://github.com/bazelbuild/bazel/tree/0e1680e58f01f3d443f7e68865b5a56b76c9dadf/tools/jdk/BUILD#L73) +rule that specifies the various options for the java compiler. So in a +BUILD file: + +```python +java_toolchain( + name = "my_toolchain", + encoding = "UTF-8", + source_version = "8", + target_version = "8", + misc = [ + "-Xep:CollectionIncompatibleType:ERROR", # http://errorprone.info/bugpattern/CollectionIncompatibleType + ], +) +``` + +And to keep it out of the tools directory (or you need to copy the rest +of the package), you can redirect the default one in a bazelrc: + +``` +build --java_toolchain=//package:my_toolchain +``` + +In the future, toolchain rules should be the configuration points for all +the languages but it is a long road. We also want to make it easier to +rebind the toolchain using the `bind` rule in the WORKSPACE file. + |