Class Checkstyle

    • Constructor Detail

      • Checkstyle

        public Checkstyle()
    • Method Detail

      • getConfigFile

        @Internal
        public java.io.File getConfigFile()
        The Checkstyle configuration file to use.
      • setConfigFile

        public void setConfigFile​(java.io.File configFile)
        The Checkstyle configuration file to use.
      • reports

        public CheckstyleReports reports​(Action<? super CheckstyleReports> configureAction)
        Configures the reports to be generated by this task. The contained reports can be configured by name and closures. Example:
         checkstyleTask {
           reports {
             html {
               destination "build/checkstyle.html"
             }
           }
         }
         
        Specified by:
        reports in interface Reporting<CheckstyleReports>
        Parameters:
        configureAction - The configuration
        Returns:
        The reports container
        Since:
        3.0
      • run

        public void run()
      • getSource

        @PathSensitive(RELATIVE)
        public FileTree getSource()
        Returns the source for this task, after the include and exclude patterns have been applied. Ignores source files which do not exist.

        The PathSensitivity for the sources is configured to be PathSensitivity.ABSOLUTE. If your sources are less strict, please change it accordingly by overriding this method in your subclass.

        The sources for this task are relatively relocatable even though it produces output that includes absolute paths. This is a compromise made to ensure that results can be reused between different builds. The downside is that up-to-date results, or results loaded from cache can show different absolute paths than would be produced if the task was executed.

        Overrides:
        getSource in class SourceTask
        Returns:
        The source.
      • getCheckstyleClasspath

        @Classpath
        public FileCollection getCheckstyleClasspath()
        The class path containing the Checkstyle library to be used.
      • setCheckstyleClasspath

        public void setCheckstyleClasspath​(FileCollection checkstyleClasspath)
        The class path containing the Checkstyle library to be used.
      • getClasspath

        @Classpath
        public FileCollection getClasspath()
        The class path containing the compiled classes for the source files to be analyzed.
      • setClasspath

        public void setClasspath​(FileCollection classpath)
        The class path containing the compiled classes for the source files to be analyzed.
      • 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

        @Nullable
        @Optional
        @Input
        public java.util.Map<java.lang.String,​java.lang.Object> getConfigProperties()
        The properties available for use in the configuration file. These are substituted into the configuration file.
      • setConfigProperties

        public void setConfigProperties​(@Nullable
                                        java.util.Map<java.lang.String,​java.lang.Object> configProperties)
        The properties available for use in the configuration file. These are substituted into the configuration file.
      • getConfigDirectory

        @PathSensitive(RELATIVE)
        @InputFiles
        public DirectoryProperty getConfigDirectory()
        Path to other Checkstyle configuration files.

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

        Returns:
        path to other Checkstyle configuration files
        Since:
        6.0
      • getMaxErrors

        @Input
        public int getMaxErrors()
        The maximum number of errors that are tolerated before breaking the build or setting the failure property.
        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

        @Input
        public int getMaxWarnings()
        The maximum number of warnings that are tolerated before breaking the build or setting the failure property.
        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

        @Console
        public boolean isShowViolations()
        Whether rule violations are to be displayed on the console.
        Returns:
        true if violations should be displayed on console
      • setShowViolations

        public void setShowViolations​(boolean showViolations)
        Whether rule violations are to be displayed on the console.
      • getEnableExternalDtdLoad

        @Incubating
        @Input
        public Property<java.lang.Boolean> getEnableExternalDtdLoad()
        Enable the use of external DTD files in configuration files. Disabled by default because this may be unsafe. See Checkstyle documentation for more details.
        Returns:
        property to enable the use of external DTD files
        Since:
        7.6
      • isIgnoreFailures

        @Internal
        public boolean isIgnoreFailures()
        Whether the build should break when the verifications performed by this task fail.
        Returns:
        true if failures should be ignored