Skip to content

Commit

Permalink
Exclude generate files from all javac lint checks (#409)
Browse files Browse the repository at this point in the history
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 <smorel@plenty.ag>
  • Loading branch information
smorel-plenty authored Nov 30, 2020
1 parent 5f20e66 commit 1bcea29
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions templates/java/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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();
Expand Down

0 comments on commit 1bcea29

Please sign in to comment.