Post Thumbnail

How to automatically enforce coding standards for a Java codebase with pre-commit

Overview

In this video tutorial, we demonstrated how to automatically enforce coding standards for a Java codebase using pre-commit, precommit4j and Checkstyle.

When working on a codebase as a team or with multiple contributors. It’s good to have an agreed-upon coding standards to guide how new code changes will occur.

Pre-commit is a development tool that runs pre-configured checks on the source code before an Engineer commits their changes locally. This way, every code change made to production will conform to the established standard.

In this tutorial, we will go through:

  1. Setting up pre-commit on the local machine
  2. Configuring pre-commit for a codebase
  3. Using precommit4j to run Checkstyle and validate Java source files
  4. Adding pre-commit check to the pipeline for guaranteed compliance

Resources

  1. Complete source code https://github.com/SeunMatt/request-v

  2. precommit4j is available here https://github.com/SeunMatt/precommit4j/

  3. pre-commit homepage https://pre-commit.com/#intro

  4. Checkstyle homage https://checkstyle.sourceforge.io/

Happy Coding

Seun Matt

Results-driven Engineer, dedicated to building elite teams that consistently achieve business objectives and drive profitability. With over 9 years of experience, spannning different facets of the FinTech space; including digital lending, consumer payment, collections and payment gateway using Java/Spring Boot technologies, PHP and Ruby on Rails