Coan is a code analysis Maven plugin that runs Checkstyle and PMD and generates a single page HTML report. You can either generate an individual report for each module or an aggregated report for all modules in a Maven project. It also logs the issues it finds to the console with links that are clickable and open the respective file in IntelliJ IDEA.
You can create a report for a single Maven project or module with the goal analyse
.
If you put the following configuration into the parent pom of a multi-module project, then plugin will generate a separate report for each module.
<build>
<plugins>
<plugin>
<groupId>ch.acanda.maven</groupId>
<artifactId>code-analysis-maven-plugin</artifactId>
<version>1.11.0</version>
<executions>
<execution>
<id>analyse-code</id>
<phase>verify</phase> <!--(1)-->
<goals>
<goal>analyse</goal>
</goals>
</execution>
</executions>
<configuration> <!--(2)-->
<skip>false</skip>
<failOnIssues>true</failOnIssues>
<pmdConfigPath>config/pmd.xml</pmdConfigPath>
<checkstyleConfigPath>config/checkstyle.xml</checkstyleConfigPath>
<targetPath>${project.build.directory}/code-analysis</targetPath>
<reportFormats>html</reportFormats>
</configuration>
</plugin>
</plugins>
</build>
-
The default phase is
verify
. This can be omitted unless you want to run the plugin in another phase. -
All configuration parameters are optional. The values in this example are the default values.
You can create an aggregated report for a multi-module Maven project with the goal aggregate
.
The goal aggregate
is not bound to a phase by default as this goal is not meant to be invoked as part of a build but individually with mvn ch.acanda.maven:code-analysis-maven-plugin:aggregate
.
If you need to change the configuration, then you can do this by either directly setting the properties on the CLI, e.g.
mvn ch.acanda.maven:code-analysis-maven-plugin:aggregate -Dcoan.failOnIssues=false
or by adding a build plugin configuration without a goal as shown below.
<build>
<plugins>
<plugin>
<groupId>ch.acanda.maven</groupId>
<artifactId>code-analysis-maven-plugin</artifactId>
<version>1.11.0</version>
<configuration> <!--(1)-->
<skip>false</skip>
<failOnIssues>true</failOnIssues>
<pmdConfigPath>config/pmd.xml</pmdConfigPath>
<checkstyleConfigPath>config/checkstyle.xml</checkstyleConfigPath>
<targetPath>${project.build.directory}/code-analysis</targetPath>
<reportFormats>html</reportFormats>
</configuration>
</plugin>
</plugins>
</build>
-
All configuration parameters are optional. The values in this example are the default values.
All parameters are optional.
- skip
-
Skips the execution when set to
true
.
Default value:false
Property:coan.skip
- failOnIssues
-
Fails the build if any of the code analysers finds any issues. If you run Maven with
--fail-at-end
, then the build will not immediately fail but only at the end of the build.
Default value:true
Property:coan.failOnIssues
- pmdConfigPath
-
The path to the PMD configuration file. This can be an absolute or relative path. If the path is relative, then the plugin tries to resolve it against the base path of the project or module that it is analysing. If it cannot resolve the path, then it recursively tries to resolve it against the parent projects. This allows you to have both a global configuration in a parent project and special configurations for selected modules.
Default value:config/pmd.xml
Property:coan.pmd.configPath
- checkstyleConfigPath
-
The path to the Checkstyle configuration file. This can be an absolute or relative path. If the path is relative, then the plugin tries to resolve it against the base path of the project or module that it is analysing. If it cannot resolve the path, then it recursively tries to resolve it against the parent projects. This allows you to have both a global configuration in a parent project and special configurations for selected modules.
Default value:config/checkstyle.xml
Property:coan.checkstyle.configPath
- targetPath
-
The working directory of the plugin. The final report(s), e.g.
report.html
, will be saved in this directory as well as some other temporary files.
Default value:${project.build.directory}/code-analysis
Property:coan.targetPath
- reportFormats
-
The plugin can create reports in different formats. This parameter contains a comma separated list of formats. The plugin detects when it is run as part of a GitHub workflow and automatically appends the report to the job’s summary.
Default value:
html
Property:coan.report.formats
The supported formats are
html
,gitlab
andgithub
:- html
-
Creates an HTML report
report.html
that lists all issues the plugin found. - gitlab
-
Creates a GitLab Code Quality report
report.gitlab.json
that you can attach as an artifact to your GitLab CI/CD job so the issues the plugin found are summarized in merge requests and the pipeline view, see artifacts:reports:codequality. - github
-
The plugin detects when it is run as part of a GitHub workflow and automatically appends the report to the job’s summary without adding this format. You only have to add
github
if you want to store the report inreport.github.md
.
The Code Analysis Maven Plugin is licensed under the Apache License, Version 2.0.