Integrating Check-style and code coverage plugin in AEM codebase

13 / Oct / 2023 by Medha Kohli 0 comments


As developers, we strive to maintain high code quality and ensure that our software is both functional and maintainable. Two essential tools for achieving this are Checkstyle and code coverage analysis. In this blog post, we’ll explore how to integrate these plugins into your Adobe Experience Manager (AEM) codebase to boost your code quality and ensure comprehensive testing coverage.

What is Checkstyle?

Checkstyle is a static code analysis tool that enforces coding conventions and best practices in your Java code. It checks your source code against predefined rules to ensure consistency and adherence to coding standards.

Why Code Coverage Matters

Code coverage analysis measures how much of your codebase is exercised by your tests. It helps identify untested or poorly tested code, reducing the risk of undetected bugs and ensuring your application behaves as expected.

Integrating Checkstyle in AEM

Integrating Checkstyle into your AEM project is straightforward and can significantly improve code quality. Here’s how to do it:

Step 1: Setting Up Your Project

First, we need to set up our AEM project. You can use the AEM Project Archetype to generate a new project. Run the following command in your terminal:

mvn -B archetype:generate \
 -D archetypeGroupId=com.adobe.aem \
 -D archetypeArtifactId=aem-project-archetype \
 -D archetypeVersion=25 \
 -D appTitle="My Site" \
 -D appId="mysite" \
 -D groupId="com.mysite" \
 -D aemVersion=6.5.5

Step 2: Define Your Checkstyle Configuration

  • Create a Checkstyle configuration file (e.g., custom-checkstyle.xml) or use an existing one.
  • Define your coding rules and standards in the configuration file. To achieve this you can create a new folder under the project you created and name it as code-analysis. create a new pom.xml file inside this folder and add below XML code to it.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""

Folder structure for reference :


Step 3: Add your custom/default check style

Note: In case you were confused which check style configuration to choose

  • Google Java Style: Google’s Java Style Guide is well-regarded in the industry, and they provide a Checkstyle configuration that enforces their coding standards. It’s known for its clarity and consistency. You can find it here
  • Sun/Oracle Checkstyle Configuration: This configuration is based on the Java Coding Style Guide by Sun Microsystems (now Oracle). It enforces many widely accepted Java coding conventions. You can find it here
  • You can customise the configuration as per your projects requirements.

Step 4: Add the code-analysis folder in the allowed modules in project’s root pom.xml


Step 5: Add the Maven Checkstyle Plugin in POM

  • Open your project’s root pom.xml file.
  • Add the Maven Checkstyle Plugin configuration to your <build><plugins> section.


  1. If you dont want your build to fail on errors, set the <failsOnError> flag to false.
  2. You can either add below code in pom or mention this command at run time – mvn clean install checkstyle:checkstyle to run your checkstyle

Step 6: You can now run mvn clean install and checkstyle will report violations in your code according to the rules you’ve defined.

You can check the error in the report generated at ../mysite/core/target/checkstyle-result.xml


Integrating Code Coverage Analysis

To ensure comprehensive code coverage, you can integrate a code coverage plugin like JaCoCo:

What is JaCoCo?

JaCoCo, short for Java Code Coverage, is an open-source code coverage tool for Java applications. Code coverage tools like JaCoCo help developers measure how much of their source code is executed by their tests.

Adding the JaCoCo Plugin

  • Open your /core/pom.xml file.
  • Add the below JaCoCo Maven Plugin configuration to your <build><plugins> section.

Note: You can set code coverage according to what your project’s requirements are. In this context, I have chosen to set a code coverage target of 70%, which aligns with our project’s quality and testing goals.

You can view the code coverage report at ../core/target/site/jacoco/index.html




Leave a Reply

Your email address will not be published. Required fields are marked *