checkstyle:checkstyle

Note:

This goal should be used as a Maven report.

Full name:

org.apache.maven.plugins:maven-checkstyle-plugin:3.5.0:checkstyle

Description:

A reporting task that performs Checkstyle analysis and generates an HTML report on any violations that Checkstyle finds.

Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: compile.
  • The goal is thread-safe and supports parallel builds.
  • Since version: 2.0.

Required Parameters

Name Type Since Description
<includeResources> boolean 2.11 Specifies whether to include the resource directories in the check.
Default: true
User Property: checkstyle.includeResources
<includeTestResources> boolean 2.11 Specifies whether to include the test resource directories in the check.
Default: true
User Property: checkstyle.includeTestResources
<includes> String - Specifies the names filter of the source files to be used for Checkstyle.
Default: **\/*.java
User Property: checkstyle.includes
<outputDirectory> File - The shared output directory for the report. Note that this parameter is only evaluated if the goal is run directly from the command line. If the goal is run indirectly as part of a site generation, the shared output directory configured in the Maven Site Plugin is used instead.

A plugin may use any subdirectory structure (either using a hard-coded name or, ideally, an additional user-defined mojo parameter with a default value) to generate multi-page reports or external reports with the main output file (entry point) denoted by #getOutputName().


Default: ${project.build.directory}/reports
<resourceIncludes> String 2.11 Specifies the names filter of the resource files to be used for Checkstyle.
Default: **/*.properties
User Property: checkstyle.resourceIncludes

Optional Parameters

Name Type Since Description
<cacheFile> String - Specifies the cache file used to speed up Checkstyle on successive runs.
Default: ${project.build.directory}/checkstyle-cachefile
<checkstyleRules> PlexusConfiguration 2.12 By using this property, you can specify the whole Checkstyle rules inline directly inside this pom.
<plugin>
  ...
  <configuration>
    <checkstyleRules>
      <module name="Checker">
        <module name="FileTabCharacter">
          <property name="eachLine" value="true" />
        </module>
        <module name="TreeWalker">
          <module name="EmptyBlock"/>
        </module>
      </module>
    </checkstyleRules>
  </configuration>
  ...
<checkstyleRulesHeader> String - The header to use for the inline configuration. Only used when you specify checkstyleRules.
Default: <?xml version="1.0"?> <!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
<configLocation> String -

Specifies the location of the XML configuration to use.

Potential values are a filesystem path, a URL, or a classpath resource. This parameter expects that the contents of the location conform to the xml format (Checkstyle Checker module) configuration of rulesets.

This parameter is resolved as resource, URL, then file. If successfully resolved, the contents of the configuration is copied into the ${project.build.directory}/checkstyle-configuration.xml file before being passed to Checkstyle as a configuration.

There are 2 predefined rulesets included in Maven Checkstyle Plugin:

  • sun_checks.xml: Sun Checks.
  • google_checks.xml: Google Checks.

Default: sun_checks.xml
User Property: checkstyle.config.location
<consoleOutput> boolean - Output errors to console.
Default: false
User Property: checkstyle.consoleOutput
<enableFilesSummary> boolean - Specifies if the Files summary should be enabled or not.
Default: true
User Property: checkstyle.enable.files.summary
<enableRulesSummary> boolean - Specifies if the Rules summary should be enabled or not.
Default: true
User Property: checkstyle.enable.rules.summary
<enableSeveritySummary> boolean - Specifies if the Severity summary should be enabled or not.
Default: true
User Property: checkstyle.enable.severity.summary
<excludeGeneratedSources> boolean 3.3.1 Specifies whether generated source files should be excluded from Checkstyle.
Default: false
User Property: checkstyle.excludeGeneratedSources
<excludes> String - Specifies the names filter of the source files to be excluded for Checkstyle.
User Property: checkstyle.excludes
<failsOnError> boolean - Specifies if the build should fail upon a violation.
Default: false
<headerLocation> String 2.0-beta-2

Specifies the location of the License file (a.k.a. the header file) that can be used by Checkstyle to verify that source code has the correct license header.

You need to use ${checkstyle.header.file} in your Checkstyle xml configuration to reference the name of this header file.

For instance:

<module name="RegexpHeader">
  <property name="headerFile" value="${checkstyle.header.file}"/>
</module>

Default: LICENSE.txt
User Property: checkstyle.header.file
<includeTestSourceDirectory> boolean 2.2 Include or not the test source directory/directories to be used for Checkstyle.
Default: false
<linkXRef> boolean 2.1 Link the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is being used.
Default: true
User Property: linkXRef
<locale> String - The locale to use when the report generation is invoked directly as a standalone Mojo.
See also: SiteTool#DEFAULT_LOCALE, SiteTool#getSiteLocales(String)
Default: default
<omitIgnoredModules> boolean 3.0.0 Specifies whether modules with a configured severity of ignore should be omitted during Checkstyle invocation.
Default: false
<outputFile> File - Specifies the path and filename to save the Checkstyle output. The format of the output file is determined by the outputFileFormat parameter.
Default: ${project.build.directory}/checkstyle-result.xml
User Property: checkstyle.output.file
<outputFileFormat> String - Specifies the format of the output to be used when writing to the output file. Valid values are "plain", "sarif" and "xml".
Default: xml
User Property: checkstyle.output.format
<outputFormat> String - The report output format: null by default, to represent a site, but can be configured to a Doxia Sink id.
User Property: output.format
<outputTimestamp> String - Timestamp for reproducible output archive entries, either formatted as ISO 8601 yyyy-MM-dd'T'HH:mm:ssXXX or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).
Default: ${project.build.outputTimestamp}
<propertiesLocation> String 2.0-beta-2

Specifies the location of the properties file.

This parameter is resolved as URL, File then resource. If successfully resolved, the contents of the properties location is copied into the ${project.build.directory}/checkstyle-checker.properties file before being passed to Checkstyle for loading.

The contents of the propertiesLocation will be made available to Checkstyle for specifying values for parameters within the xml configuration (specified in the configLocation parameter).


User Property: checkstyle.properties.location
<propertyExpansion> String - Allows for specifying raw property expansion information.
<resourceExcludes> String 2.11 Specifies the names filter of the resource files to be excluded for Checkstyle.
User Property: checkstyle.resourceExcludes
<rulesFiles> File - Dump file for inlined Checkstyle rules.
Default: ${project.build.directory}/checkstyle-rules.xml
User Property: checkstyle.output.rules.file
<siteDirectory> File - Directory containing the site.xml file.
Default: ${basedir}/src/site
<skip> boolean 2.2 Skip entire check.
Default: false
User Property: checkstyle.skip
<sourceDirectories> List<String> 2.13 Specifies the location of the source directories to be used for Checkstyle. Default value is ${project.compileSourceRoots}.
<sourceDirectory> File -
Deprecated.
instead use sourceDirectories. For version 3.0.0, this parameter is only defined to break the build if you use it!

Specifies the location of the source directory to be used for Checkstyle.
<suppressionsFileExpression> String 2.1 The key to be used in the properties for the suppressions file.
Default: checkstyle.suppressions.file
User Property: checkstyle.suppression.expression
<suppressionsLocation> String 2.0-beta-2

Specifies the location of the suppressions XML file to use.

This parameter is resolved as resource, URL, then file. If successfully resolved, the contents of the suppressions XML is copied into the ${project.build.directory}/checkstyle-supressions.xml file before being passed to Checkstyle for loading.

See suppressionsFileExpression for the property that will be made available to your Checkstyle configuration.


User Property: checkstyle.suppressions.location
<testSourceDirectories> List<String> 2.13 Specifies the location of the test source directories to be used for Checkstyle. Default value is ${project.testCompileSourceRoots}.
<testSourceDirectory> File 2.2
Deprecated.
instead use testSourceDirectories. For version 3.0.0, this parameter is only defined to break the build if you use it!

Specifies the location of the test source directory to be used for Checkstyle.
<treeWalkerNames> List<String> 2.11 When using custom treeWalkers, specify their names here so the checks inside the treeWalker end up the the rule-summary.
<useFile> File - If null, the Checkstyle plugin will display violations on stdout. Otherwise, a text file will be created with the violations.
<xrefLocation> File - Location where Source XRef is generated for this project.
Default: org.apache.maven.reporting.AbstractMavenReport.getReportOutputDirectory() + /xref
<xrefTestLocation> File - Location where Test Source XRef is generated for this project.
Default: org.apache.maven.reporting.AbstractMavenReport.getReportOutputDirectory() + /xref-test

Parameter Details

<cacheFile>

Specifies the cache file used to speed up Checkstyle on successive runs.
  • Type: java.lang.String
  • Required: No
  • Default: ${project.build.directory}/checkstyle-cachefile

<checkstyleRules>

By using this property, you can specify the whole Checkstyle rules inline directly inside this pom.
<plugin>
  ...
  <configuration>
    <checkstyleRules>
      <module name="Checker">
        <module name="FileTabCharacter">
          <property name="eachLine" value="true" />
        </module>
        <module name="TreeWalker">
          <module name="EmptyBlock"/>
        </module>
      </module>
    </checkstyleRules>
  </configuration>
  ...
  • Type: org.codehaus.plexus.configuration.PlexusConfiguration
  • Since: 2.12
  • Required: No

<checkstyleRulesHeader>

The header to use for the inline configuration. Only used when you specify checkstyleRules.
  • Type: java.lang.String
  • Required: No
  • Default: <?xml version="1.0"?> <!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">

<configLocation>

Specifies the location of the XML configuration to use.

Potential values are a filesystem path, a URL, or a classpath resource. This parameter expects that the contents of the location conform to the xml format (Checkstyle Checker module) configuration of rulesets.

This parameter is resolved as resource, URL, then file. If successfully resolved, the contents of the configuration is copied into the ${project.build.directory}/checkstyle-configuration.xml file before being passed to Checkstyle as a configuration.

There are 2 predefined rulesets included in Maven Checkstyle Plugin:

  • sun_checks.xml: Sun Checks.
  • google_checks.xml: Google Checks.
  • Type: java.lang.String
  • Required: No
  • User Property: checkstyle.config.location
  • Default: sun_checks.xml

<consoleOutput>

Output errors to console.
  • Type: boolean
  • Required: No
  • User Property: checkstyle.consoleOutput
  • Default: false

<enableFilesSummary>

Specifies if the Files summary should be enabled or not.
  • Type: boolean
  • Required: No
  • User Property: checkstyle.enable.files.summary
  • Default: true

<enableRulesSummary>

Specifies if the Rules summary should be enabled or not.
  • Type: boolean
  • Required: No
  • User Property: checkstyle.enable.rules.summary
  • Default: true

<enableSeveritySummary>

Specifies if the Severity summary should be enabled or not.
  • Type: boolean
  • Required: No
  • User Property: checkstyle.enable.severity.summary
  • Default: true

<excludeGeneratedSources>

Specifies whether generated source files should be excluded from Checkstyle.
  • Type: boolean
  • Since: 3.3.1
  • Required: No
  • User Property: checkstyle.excludeGeneratedSources
  • Default: false

<excludes>

Specifies the names filter of the source files to be excluded for Checkstyle.
  • Type: java.lang.String
  • Required: No
  • User Property: checkstyle.excludes

<failsOnError>

Specifies if the build should fail upon a violation.
  • Type: boolean
  • Required: No
  • Default: false

<headerLocation>

Specifies the location of the License file (a.k.a. the header file) that can be used by Checkstyle to verify that source code has the correct license header.

You need to use ${checkstyle.header.file} in your Checkstyle xml configuration to reference the name of this header file.

For instance:

<module name="RegexpHeader">
  <property name="headerFile" value="${checkstyle.header.file}"/>
</module>
  • Type: java.lang.String
  • Since: 2.0-beta-2
  • Required: No
  • User Property: checkstyle.header.file
  • Default: LICENSE.txt

<includeResources>

Specifies whether to include the resource directories in the check.
  • Type: boolean
  • Since: 2.11
  • Required: Yes
  • User Property: checkstyle.includeResources
  • Default: true

<includeTestResources>

Specifies whether to include the test resource directories in the check.
  • Type: boolean
  • Since: 2.11
  • Required: Yes
  • User Property: checkstyle.includeTestResources
  • Default: true

<includeTestSourceDirectory>

Include or not the test source directory/directories to be used for Checkstyle.
  • Type: boolean
  • Since: 2.2
  • Required: No
  • Default: false

<includes>

Specifies the names filter of the source files to be used for Checkstyle.
  • Type: java.lang.String
  • Required: Yes
  • User Property: checkstyle.includes
  • Default: **\/*.java

<linkXRef>

Link the violation line numbers to the (Test) Source XRef. Links will be created automatically if the JXR plugin is being used.
  • Type: boolean
  • Since: 2.1
  • Required: No
  • User Property: linkXRef
  • Default: true

<locale>

The locale to use when the report generation is invoked directly as a standalone Mojo.
See also: SiteTool#DEFAULT_LOCALE, SiteTool#getSiteLocales(String)
  • Type: java.lang.String
  • Required: No
  • Default: default

<omitIgnoredModules>

Specifies whether modules with a configured severity of ignore should be omitted during Checkstyle invocation.
  • Type: boolean
  • Since: 3.0.0
  • Required: No
  • Default: false

<outputDirectory>

The shared output directory for the report. Note that this parameter is only evaluated if the goal is run directly from the command line. If the goal is run indirectly as part of a site generation, the shared output directory configured in the Maven Site Plugin is used instead.

A plugin may use any subdirectory structure (either using a hard-coded name or, ideally, an additional user-defined mojo parameter with a default value) to generate multi-page reports or external reports with the main output file (entry point) denoted by #getOutputName().

  • Type: java.io.File
  • Required: Yes
  • Default: ${project.build.directory}/reports

<outputFile>

Specifies the path and filename to save the Checkstyle output. The format of the output file is determined by the outputFileFormat parameter.
  • Type: java.io.File
  • Required: No
  • User Property: checkstyle.output.file
  • Default: ${project.build.directory}/checkstyle-result.xml

<outputFileFormat>

Specifies the format of the output to be used when writing to the output file. Valid values are "plain", "sarif" and "xml".
  • Type: java.lang.String
  • Required: No
  • User Property: checkstyle.output.format
  • Default: xml

<outputFormat>

The report output format: null by default, to represent a site, but can be configured to a Doxia Sink id.
  • Type: java.lang.String
  • Required: No
  • User Property: output.format

<outputTimestamp>

Timestamp for reproducible output archive entries, either formatted as ISO 8601 yyyy-MM-dd'T'HH:mm:ssXXX or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).
  • Type: java.lang.String
  • Required: No
  • Default: ${project.build.outputTimestamp}

<propertiesLocation>

Specifies the location of the properties file.

This parameter is resolved as URL, File then resource. If successfully resolved, the contents of the properties location is copied into the ${project.build.directory}/checkstyle-checker.properties file before being passed to Checkstyle for loading.

The contents of the propertiesLocation will be made available to Checkstyle for specifying values for parameters within the xml configuration (specified in the configLocation parameter).

  • Type: java.lang.String
  • Since: 2.0-beta-2
  • Required: No
  • User Property: checkstyle.properties.location

<propertyExpansion>

Allows for specifying raw property expansion information.
  • Type: java.lang.String
  • Required: No

<resourceExcludes>

Specifies the names filter of the resource files to be excluded for Checkstyle.
  • Type: java.lang.String
  • Since: 2.11
  • Required: No
  • User Property: checkstyle.resourceExcludes

<resourceIncludes>

Specifies the names filter of the resource files to be used for Checkstyle.
  • Type: java.lang.String
  • Since: 2.11
  • Required: Yes
  • User Property: checkstyle.resourceIncludes
  • Default: **/*.properties

<rulesFiles>

Dump file for inlined Checkstyle rules.
  • Type: java.io.File
  • Required: No
  • User Property: checkstyle.output.rules.file
  • Default: ${project.build.directory}/checkstyle-rules.xml

<siteDirectory>

Directory containing the site.xml file.
  • Type: java.io.File
  • Required: No
  • Default: ${basedir}/src/site

<skip>

Skip entire check.
  • Type: boolean
  • Since: 2.2
  • Required: No
  • User Property: checkstyle.skip
  • Default: false

<sourceDirectories>

Specifies the location of the source directories to be used for Checkstyle. Default value is ${project.compileSourceRoots}.
  • Type: java.util.List<java.lang.String>
  • Since: 2.13
  • Required: No

<sourceDirectory>

Deprecated.
instead use sourceDirectories. For version 3.0.0, this parameter is only defined to break the build if you use it!

Specifies the location of the source directory to be used for Checkstyle.
  • Type: java.io.File
  • Required: No

<suppressionsFileExpression>

The key to be used in the properties for the suppressions file.
  • Type: java.lang.String
  • Since: 2.1
  • Required: No
  • User Property: checkstyle.suppression.expression
  • Default: checkstyle.suppressions.file

<suppressionsLocation>

Specifies the location of the suppressions XML file to use.

This parameter is resolved as resource, URL, then file. If successfully resolved, the contents of the suppressions XML is copied into the ${project.build.directory}/checkstyle-supressions.xml file before being passed to Checkstyle for loading.

See suppressionsFileExpression for the property that will be made available to your Checkstyle configuration.

  • Type: java.lang.String
  • Since: 2.0-beta-2
  • Required: No
  • User Property: checkstyle.suppressions.location

<testSourceDirectories>

Specifies the location of the test source directories to be used for Checkstyle. Default value is ${project.testCompileSourceRoots}.
  • Type: java.util.List<java.lang.String>
  • Since: 2.13
  • Required: No

<testSourceDirectory>

Deprecated.
instead use testSourceDirectories. For version 3.0.0, this parameter is only defined to break the build if you use it!

Specifies the location of the test source directory to be used for Checkstyle.
  • Type: java.io.File
  • Since: 2.2
  • Required: No

<treeWalkerNames>

When using custom treeWalkers, specify their names here so the checks inside the treeWalker end up the the rule-summary.
  • Type: java.util.List<java.lang.String>
  • Since: 2.11
  • Required: No

<useFile>

If null, the Checkstyle plugin will display violations on stdout. Otherwise, a text file will be created with the violations.
  • Type: java.io.File
  • Required: No

<xrefLocation>

Location where Source XRef is generated for this project.
Default: org.apache.maven.reporting.AbstractMavenReport.getReportOutputDirectory() + /xref
  • Type: java.io.File
  • Required: No

<xrefTestLocation>

Location where Test Source XRef is generated for this project.
Default: org.apache.maven.reporting.AbstractMavenReport.getReportOutputDirectory() + /xref-test
  • Type: java.io.File
  • Required: No