From 1bcea29601b5624234a19b3d7f0ebd9e9984f583 Mon Sep 17 00:00:00 2001 From: Shawn Morel <58961104+smorel-plenty@users.noreply.github.com> Date: Sun, 29 Nov 2020 19:51:54 -0800 Subject: [PATCH] Exclude generate files from all javac lint checks (#409) The default gradle protobuf plugin includes the generated java sources in the same `compileJava` task that your own sources live. IF you want to turn on any `javac -Xlint` options or `-Werror` you need to completely refactor your gradle project to have a separate sub-project containing just the protos. Separately, the generated java code should probably strive to pass all javac lint checks but at least this change allows the generated files to be excluded (this is a similar approach used by Jooq and immutables java). Signed-off-by: Shawn Morel --- templates/java/file.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/java/file.go b/templates/java/file.go index 506e0b197..567831cf4 100644 --- a/templates/java/file.go +++ b/templates/java/file.go @@ -4,7 +4,9 @@ const fileTpl = `// Code generated by protoc-gen-validate. DO NOT EDIT. // source: {{ .File.InputPath }} package {{ javaPackage .File }}; + {{ if isOfFileType . }} +@SuppressWarnings("all") public class {{ classNameFile . }}Validator { public static io.envoyproxy.pgv.ValidatorImpl validatorFor(Class clazz) { {{ range .AllMessages }} @@ -23,6 +25,7 @@ public class {{ classNameFile . }}Validator { /** * Validates {@code {{ simpleName . }}} protobuf objects. */ +@SuppressWarnings("all") public class {{ classNameMessage .}}Validator implements io.envoyproxy.pgv.ValidatorImpl<{{ qualifiedName . }}>{ public static io.envoyproxy.pgv.ValidatorImpl validatorFor(Class clazz) { if (clazz.equals({{ qualifiedName . }}.class)) return new {{ simpleName .}}Validator();