google / google/google-java-format

How to run google-java-format from Bazel?

Đang mở
#917 9 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
6.2k
Fork
937
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
3

Mô tả

I would like to run `google-java-format` in an (open source) project which uses Bazel as build system.

I currently have it set up using https://github.com/dustinsand/pre-commit-jvm (with https://pre-commit.com) but it strikes me as "odd" having to install https://get-coursier.io and relying on `dustinsand/pre-commit-jvm` when it should be possible to "just" have a (Maven) dependency on this in Bazel and "run it" - I'm just not entirely sure HOW one would be run a Java based tool like this one from Bazel...

... I have briefly explored something like what [this post on `bazel-discuss`](https://groups.google.com/g/bazel-discuss/c/eQTAycAqi1g/m/AJIv7uDqBgAJ) may have been after, and started to write my own `GoogleJavaFormatTest` using this project's API, but it doesn't seem to be intended to used like that (`UsageException` is package local only, even though `Main#format(String... args) throws UsageException`) - and integrated this as a `b test //...` is perhaps that's the wrong way to go about this anyway?

How would one best run google-java-format from Bazel? You would want it "run whenever any *.java changed", and one would want it to fail the build if the formatting was wrong - but re-write (correct) the source files. Is this possible with Bazel? How does one even "run a main() method from a dependency" for something like this?

@cushon perhaps you have some wise guidance?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.