You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. On Git hook pre-commit
Maven plugin for installing hooks: https://github.com/rudikershaw/git-build-hook
This requires running a manual command to turn a bash file into an executable one.
Maven plugin for code formatting: See option 2
Options for the pre-commit hook (some complications could appear for handling staged and non-staged files):
For Automation Mechanism we are selecting On Maven Build because it is less intrusive than the others, and we are selecting the Spotless Maven plugin because it is a more mature tool than the other, and it provides support for the four Java style options.
For Java Style we are selecting Eclipse because it allows flexible customization and it is the only style used by major IDEs (IntelliJ, VSCode, Eclipse) to exchange formatting. So, Spotless will be configured to use Eclipse as a Java formatter.
Spotless comes with two Maven commands that you can run at any moment, preferably before committing your changes:
mvn spotless:check to verify if code is formatted correctly.
mvn spotless:apply to rewrite the source code in place.
In the build Github Action a new step will be added to check the code formatting, so the build will fail if the code isn't formatted correctly.
Automation Mechanism
We have some options to automate code formatting:
1. On Git hook pre-commit
Maven plugin for installing hooks:
https://github.com/rudikershaw/git-build-hook
This requires running a manual command to turn a bash file into an executable one.
Maven plugin for code formatting: See option 2
Options for the pre-commit hook (some complications could appear for handling staged and non-staged files):
2. On Maven build
Maven plugins for code formatting:
Since 2014, 4k stars, 176 contributors
Wrapper to prettier-java. Node, prettier, and prettier-java are downloaded automatically as needed.
Prettier-Java: since 2019, 1k stars, 29 contributors
3. On Github pull request
Github action for code formatting:
https://github.com/marketplace/actions/google-java-format
Java Style
Regarding Java style, we have three candidates which come from the same Google family:
indent 2 spaces, 100 chars by line, old fashioned for lambdas
indent 4 spaces, 100 chars by line, old fashioned for lambdas
indent 4 spaces, 120/80 chars by line, lambda friendly.
We could consider a fourth option:
Where you can customize almost every detail: indent, char per line, lambdas, method chaining, etc.
The text was updated successfully, but these errors were encountered: