checkstyle:check

Full name:

org.apache.maven.plugins:maven-checkstyle-plugin:2.7:check

Description:

Perform a violation check against the last Checkstyle run to see if there are any violations. It reads the Checkstyle output file, counts the number of violations found and displays it on the console.

Attributes:

  • Requires a Maven project to be executed.
  • Requires dependency resolution of artifacts in scope: test.
  • The goal is thread-safe and supports parallel builds.
  • Binds by default to the lifecycle phase: verify.

Required Parameters

Name Type Since Description
includes String - Specifies the names filter of the source files to be used for Checkstyle.
Default value is: **/*.java.
sourceDirectory File - Specifies the location of the source directory to be used for Checkstyle.
Default value is: ${project.build.sourceDirectory}.

Optional Parameters

Name Type Since Description
cacheFile String - Specifies the cache file used to speed up Checkstyle on successive runs.
Default value is: ${project.build.directory}/checkstyle-cachefile.
configLocation String 2.5

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 4 predefined rulesets.

  • config/sun_checks.xml: Sun Checks.
  • config/turbine_checks.xml: Turbine Checks.
  • config/avalon_checks.xml: Avalon Checks.
  • config/maven_checks.xml: Maven Source Checks.

Default value is: config/sun_checks.xml.
consoleOutput boolean - Output errors to console.
Default value is: false.
encoding String 2.2 The file encoding to use when reading the source files. If the property project.build.sourceEncoding is not set, the platform default encoding is used. Note: This parameter always overrides the property charset from Checkstyle's TreeWalker module.
Default value is: ${project.build.sourceEncoding}.
excludes String - Specifies the names filter of the source files to be excluded for Checkstyle.
failOnViolation boolean - Do we fail the build on a violation?
Default value is: true.
failsOnError boolean - Specifies if the build should fail upon a violation.
Default value is: 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 value is: LICENSE.txt.
includeTestSourceDirectory boolean 2.2 Include or not the test source directory to be used for Checkstyle.
Default value is: ${false}.
logViolationsToConsole boolean 2.3 Output the detected violations to the console.
Default value is: false.
maxAllowedViolations int 2.3 The maximum number of allowed violations. The execution fails only if the number of violations is above this limit.
Default value is: 0.
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 value is: ${project.build.directory}/checkstyle-result.xml.
outputFileFormat String - Specifies the format of the output to be used when writing to the output file. Valid values are "plain" and "xml".
Default value is: xml.
propertiesLocation String 2.5

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).


propertyExpansion String - Allows for specifying raw property expansion information.
skip boolean 2.2 Skip entire check.
Default value is: false.
skipExec boolean 2.5 Skip checktyle execution will only scan the outputFile.
Default value is: false.
suppressionsFileExpression String 2.1 The key to be used in the properties for the suppressions file.
Default value is: checkstyle.suppressions.file.
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.


testSourceDirectory File 2.2 Specifies the location of the test source directory to be used for Checkstyle.
Default value is: ${project.build.testSourceDirectory}.
useFile File - If null, the Checkstyle plugin will display violations on stdout. Otherwise, a text file will be created with the violations.
violationSeverity String 2.2 The lowest severity level that is considered a violation. Valid values are "error", "warning" and "info".
Default value is: error.

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

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 4 predefined rulesets.

  • config/sun_checks.xml: Sun Checks.
  • config/turbine_checks.xml: Turbine Checks.
  • config/avalon_checks.xml: Avalon Checks.
  • config/maven_checks.xml: Maven Source Checks.
  • Type: java.lang.String
  • Since: 2.5
  • Required: No
  • Expression: ${checkstyle.config.location}
  • Default: config/sun_checks.xml

consoleOutput:

Output errors to console.
  • Type: boolean
  • Required: No
  • Default: false

encoding:

The file encoding to use when reading the source files. If the property project.build.sourceEncoding is not set, the platform default encoding is used. Note: This parameter always overrides the property charset from Checkstyle's TreeWalker module.
  • Type: java.lang.String
  • Since: 2.2
  • Required: No
  • Expression: ${encoding}
  • Default: ${project.build.sourceEncoding}

excludes:

Specifies the names filter of the source files to be excluded for Checkstyle.
  • Type: java.lang.String
  • Required: No
  • Expression: ${checkstyle.excludes}

failOnViolation:

Do we fail the build on a violation?
  • Type: boolean
  • Required: No
  • Expression: ${checkstyle.failOnViolation}
  • Default: true

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
  • Expression: ${checkstyle.header.file}
  • Default: LICENSE.txt

includeTestSourceDirectory:

Include or not the test source directory 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
  • Expression: ${checkstyle.includes}
  • Default: **/*.java

logViolationsToConsole:

Output the detected violations to the console.
  • Type: boolean
  • Since: 2.3
  • Required: No
  • Expression: ${checkstyle.console}
  • Default: false

maxAllowedViolations:

The maximum number of allowed violations. The execution fails only if the number of violations is above this limit.
  • Type: int
  • Since: 2.3
  • Required: No
  • Expression: ${checkstyle.maxAllowedViolations}
  • Default: 0

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
  • Expression: ${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" and "xml".
  • Type: java.lang.String
  • Required: No
  • Expression: ${checkstyle.output.format}
  • Default: xml

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.5
  • Required: No
  • Expression: ${checkstyle.properties.location}

propertyExpansion:

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

skip:

Skip entire check.
  • Type: boolean
  • Since: 2.2
  • Required: No
  • Expression: ${checkstyle.skip}
  • Default: false

skipExec:

Skip checktyle execution will only scan the outputFile.
  • Type: boolean
  • Since: 2.5
  • Required: No
  • Expression: ${checkstyle.skipExec}
  • Default: false

sourceDirectory:

Specifies the location of the source directory to be used for Checkstyle.
  • Type: java.io.File
  • Required: Yes
  • Default: ${project.build.sourceDirectory}

suppressionsFileExpression:

The key to be used in the properties for the suppressions file.
  • Type: java.lang.String
  • Since: 2.1
  • Required: No
  • Expression: ${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
  • Expression: ${checkstyle.suppressions.location}

testSourceDirectory:

Specifies the location of the test source directory to be used for Checkstyle.
  • Type: java.io.File
  • Since: 2.2
  • Required: No
  • Default: ${project.build.testSourceDirectory}

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

violationSeverity:

The lowest severity level that is considered a violation. Valid values are "error", "warning" and "info".
  • Type: java.lang.String
  • Since: 2.2
  • Required: No
  • Expression: ${checkstyle.violationSeverity}
  • Default: error