A maven plugin that automatically deploys google-java-format code formatter as a pre-commit
git hook.
On commit, the hook will automatically format staged java files.
Add this to your maven project root pom.xml :
<build> <plugins> <plugin> <groupId>com.cosium.code</groupId> <artifactId>maven-git-code-format</artifactId> <version>${maven-git-code-format.version}</version> <executions> <execution> <goals> <goal>install-hooks</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
mvn git-code-format:format-code -DglobPattern=**/*
mvn git-code-format:validate-code-format -DglobPattern=**/*
On the initialize
maven phase, git-code-format:install-hooks
installs a git pre-commit
hook that looks like this :
#!/bin/bash /usr/share/apache-maven-3.5.0/bin/mvn git-code-format:on-pre-commit
On pre-commit
git phase, the hook triggers the git-code-format:on-pre-commit
which formats the code of the modified java files using google-java-format
.