# Class CheckstyleExtension

java.lang.Object
org.gradle.api.plugins.quality.CodeQualityExtension
org.gradle.api.plugins.quality.CheckstyleExtension

public abstract class CheckstyleExtension extends CodeQualityExtension
Configuration options for the Checkstyle plugin.

Since:
  1.0
See Also:
  - `CheckstylePlugin`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CheckstyleExtension(Project project)`
  Creates a new `CheckstyleExtension`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `TextResource`
  `getConfig()`
  The Checkstyle configuration to use.
  `abstract DirectoryProperty`
  `getConfigDirectory()`
  Path to other Checkstyle configuration files.
  `File`
  `getConfigFile()`
  The Checkstyle configuration file to use.
  `Map<String,Object>`
  `getConfigProperties()`
  The properties available for use in the configuration file.
  `abstract Property<Boolean>`
  `getEnableExternalDtdLoad()`
  Enable the ability to use custom DTD files in config and load them from some location on all checkstyle tasks in this project.
  `int`
  `getMaxErrors()`
  The maximum number of errors that are tolerated before breaking the build or setting the failure property.
  `int`
  `getMaxWarnings()`
  The maximum number of warnings that are tolerated before breaking the build or setting the failure property.
  `boolean`
  `isShowViolations()`
  Whether rule violations are to be displayed on the console.
  `void`
  `setConfig(TextResource config)`
  The Checkstyle configuration to use.
  `void`
  `setConfigFile(File configFile)`
  The Checkstyle configuration file to use.
  `void`
  `setConfigProperties(Map<String,Object> configProperties)`
  The properties available for use in the configuration file.
  `void`
  `setMaxErrors(int maxErrors)`
  Set the maximum number of errors that are tolerated before breaking the build.
  `void`
  `setMaxWarnings(int maxWarnings)`
  Set the maximum number of warnings that are tolerated before breaking the build.
  `void`
  `setShowViolations(boolean showViolations)`
  Whether rule violations are to be displayed on the console.

  ### Methods inherited from class CodeQualityExtension

  `getObjectFactory, getReportsDir, getReportsDirectory, getSourceSets, getToolVersion, isIgnoreFailures, setIgnoreFailures, setReportsDir, setSourceSets, setToolVersion`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### CheckstyleExtension

    public CheckstyleExtension(Project project)
    Creates a new `CheckstyleExtension`.
    Since:
      2.2

- ## Method Details

  - ### getConfigFile

    public File getConfigFile()
    The Checkstyle configuration file to use.
    Since:
      1.0

  - ### setConfigFile

    public void setConfigFile(File configFile)
    The Checkstyle configuration file to use.
    Since:
      1.0

  - ### getConfig

    public TextResource getConfig()
    The Checkstyle configuration to use. Replaces the `configFile` property.
    Since:
      2.2

  - ### setConfig

    public void setConfig(TextResource config)
    The Checkstyle configuration to use. Replaces the `configFile` property.
    Since:
      2.2

  - ### getConfigProperties

    public Map<String,Object> getConfigProperties()
    The properties available for use in the configuration file. These are substituted into the configuration file.
    Since:
      1.0

  - ### setConfigProperties

    public void setConfigProperties(Map<String,Object> configProperties)
    The properties available for use in the configuration file. These are substituted into the configuration file.
    Since:
      1.0

  - ### getConfigDirectory

    public abstract DirectoryProperty getConfigDirectory()
    Path to other Checkstyle configuration files. By default, this path is `$rootProject.projectDir/config/checkstyle`

    This path will be exposed as the variable `config_loc` in Checkstyle's configuration files.

    Returns:
      path to other Checkstyle configuration files
    Since:
      4.7

  - ### getMaxErrors

    public int getMaxErrors()
    The maximum number of errors that are tolerated before breaking the build or setting the failure property. Defaults to `0`.

    Example: maxErrors = 42

    Returns:
      the maximum number of errors allowed
    Since:
      3.4

  - ### setMaxErrors

    public void setMaxErrors(int maxErrors)
    Set the maximum number of errors that are tolerated before breaking the build.
    Parameters:
      `maxErrors` - number of errors allowed
    Since:
      3.4

  - ### getMaxWarnings

    public int getMaxWarnings()
    The maximum number of warnings that are tolerated before breaking the build or setting the failure property. Defaults to `Integer.MAX_VALUE`.

    Example: maxWarnings = 1000

    Returns:
      the maximum number of warnings allowed
    Since:
      3.4

  - ### setMaxWarnings

    public void setMaxWarnings(int maxWarnings)
    Set the maximum number of warnings that are tolerated before breaking the build.
    Parameters:
      `maxWarnings` - number of warnings allowed
    Since:
      3.4

  - ### isShowViolations

    public boolean isShowViolations()
    Whether rule violations are to be displayed on the console. Defaults to `true`. Example: showViolations = false
    Since:
      1.4

  - ### setShowViolations

    public void setShowViolations(boolean showViolations)
    Whether rule violations are to be displayed on the console. Defaults to `true`. Example: showViolations = false
    Since:
      1.4

  - ### getEnableExternalDtdLoad

    @Incubating @Optional @Input public abstract Property<Boolean> getEnableExternalDtdLoad()
    Enable the ability to use custom DTD files in config and load them from some location on all checkstyle tasks in this project. Disabled by default due to security concerns. See Checkstyle documentation for more details.
    Returns:
      The property controlling whether to enable the ability to use custom DTD files
    Since:
      7.6