google / google/google-java-format

How to run google-java-format from Bazel?

Aberta
#917 9 comentários 1 reação 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Linguagem predominante
Java
Estrelas
6.2k
Forks
936
Merge médio
6min
PRs com merge (30d)
3

Descrição

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?

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece pelo contexto de Bazel e pre-commit na issue e, em seguida, inspecione Main#format(String... args) do google-java-format e o GoogleJavaFormatTest proposto. O trabalho estará concluído quando houver um workflow do Bazel documentado e reproduzível que execute o formatador nos arquivos Java alterados e defina o comportamento esperado do build.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
java
Domínio
build-system
Tipo de issue
Documentação
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Precisa de esclarecimento
Facilidade para iniciantes
25/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.