Wim Deblauwe
Wim Deblauwe

Reputation: 26878

How to fully disable javadoc checking with checkstyle maven plugin

i want to use the Maven Checkstyle plugin with a custom configuration that tells Checkstyle to not warn or error on missing Javadoc. Is there a way to do this?

Upvotes: 15

Views: 20385

Answers (3)

Sanjay Bharwani
Sanjay Bharwani

Reputation: 4839

Below is the example with the Gradle 7.3.2 setup.

build.gradle

 plugins {
    id 'checkstyle'
}

Folder structure (root level).

    ├── config
    └── checkstyle
        ├── checkstyle.xml
        └── suppressions.xml

Below is the entry in checkstyle.xml to include suppressions.xml

<module name="SuppressionFilter">
    <property name="file" value="${config_loc}/suppressions.xml" />
</module>

And now you can have the suppressions in the suppressions.xml file to ignore a particular type of check.

for e.g. Below code base will ignore the mentioned checks for all files (regex can be applied to ignore particular matching set of files.)

 <suppressions>
    <suppress files="." checks="JavadocMethod"/>
    <suppress files="." checks="JavadocPackage"/>
    <suppress files="." checks="JavadocVariable"/>
    <suppress files="." checks="MissingJavadocMethod"/>
    <suppress files="." checks="JavadocPackage"/>
</suppressions>

Now execute the Checkstyle task on consolidated project files by

gradle check

If specific execution is needed then use checkstyleMain or checkStyleTest to execute checkstyle report on Source files or test files respectively.

Upvotes: 2

Matheus Santana
Matheus Santana

Reputation: 581

One good option would be configuring a suppressions filter.

Plugin configuration:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <!-- ... -->
  <build>
    <plugins>
      <!-- ... -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.17</version>
        <executions>
          <execution>
            <id>verify</id>
            <phase>verify</phase>
            <configuration>
              <encoding>UTF-8</encoding>
              <consoleOutput>true</consoleOutput>
              <failsOnError>true</failsOnError>
              <linkXRef>false</linkXRef>
              <suppressionsLocation>
                checkstyle-suppressions.xml
              </suppressionsLocation>
              <suppressionsFileExpression>
                checkstyle.suppressions.file
              </suppressionsFileExpression>
            </configuration>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <!-- ... -->
</project>

checkstyle-suppressions.xml file:

<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
     "-//Puppy Crawl//DTD Suppressions 1.0//EN"
     "http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">

<suppressions>
  <suppress checks="Javadoc" files="."/>
</suppressions>

Then running

$ mvn verify

Does not output any Javadoc-related Checkstyle errors.

Many other examples on suppressions filters may be found in checkstyle repository.

Upvotes: 13

Wim Deblauwe
Wim Deblauwe

Reputation: 26878

Just found it myself. To fully ignore all javadoc checking for everthing, add this to your checkstyle configuration:

    <!-- No need for Javadoc -->
    <module name="JavadocType">
        <property name="severity" value="ignore"/>
    </module>
    <module name="JavadocMethod">
        <property name="severity" value="ignore"/>
    </module>
    <module name="JavadocVariable">
        <property name="severity" value="ignore"/>
    </module>

Upvotes: 14

Related Questions