Закоулки мозга

Корневой pom.xml

<properties>
    ...
    <checkstyle.config.file.path>config/checkstyle.xml</checkstyle.config.file.path>
    <checkstyle.supressions.path>config/checkstyle-suppressions.xml</checkstyle.supressions.path>
    <findbugs.annotation>3.0.1</findbugs.annotation>
    ...
</properties>

<dependencies>
    ...
    <dependency>
        <groupId>com.google.code.findbugs</groupId>
        <artifactId>annotations</artifactId>
        <version>${findbugs.annotation}</version>
    </dependency>
    ...
</dependencies>

<build>
    <pluginManagement>
        <plugins>
            ...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <configLocation>${checkstyle.config.file.path}</configLocation>
                    <suppressionsLocation>${checkstyle.supressions.path}</suppressionsLocation>
                    <consoleOutput>true</consoleOutput>
                    <excludes>**/generated**/**</excludes>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            ...
        </plugins>
    </pluginManagement>
</build>

<profiles>
    ...
    <profile>
        <id>code-check</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <inherited>false</inherited>
                    <executions>
                        <execution>
                            <!--This matches and thus overrides-->
                            <id>checkstyle</id>
                            <phase>none</phase>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-pmd-plugin</artifactId>
                    <version>3.8</version>
                    <configuration>
                        <targetJdk>${jdk.version}</targetJdk>
                        <verbose>true</verbose>
                        <excludes>
                            <excludes>**/generated/**/*</excludes>
                        </excludes>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.5</version>
                    <configuration>
                        <!--
                            Enables analysis which takes more memory but finds more bugs.
                            If you run out of memory, changes the value of the effort element
                            to 'low'.
                        -->
                        <effort>Max</effort>
                        <!-- Reports all bugs (other values are medium and max) -->
                        <threshold>Low</threshold>
                        <!-- Produces XML report -->
                        <xmlOutput>true</xmlOutput>
                        <findbugsXmlOutputDirectory>${project.build.directory}/findbugs</findbugsXmlOutputDirectory>
                        <excludeFilterFile>${project.basedir}/../config/findbugs-exclude.xml</excludeFilterFile>
                    </configuration>
                    <executions>
                        <!-- Ensures that FindBugs inspects source code when project is compiled. -->
                        <execution>
                            <id>analyze-compile</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    ...
</profiles>

config\checkstyle.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Puppy Crawl//DTD Check Configuration 1.1//EN"
        "http://www.puppycrawl.com/dtds/configuration_1_1.dtd">

<!-- commons lang customization of default Checkstyle behavior -->
<module name="Checker">
    <property name="localeLanguage" value="en"/>
    <module name="FileTabCharacter">
        <property name="fileExtensions" value="java,xml"/>
    </module>
    <module name="TreeWalker">
        <module name="EmptyStatement"/>
        <!--module name="EmptyBlock"/-->
        <module name="LeftCurly"/>
        <module name="NeedBraces"/>
        <module name="RightCurly"/>
        <module name="AvoidNestedBlocks"/>
        <module name="HiddenField">
            <property name="tokens" value="VARIABLE_DEF"/>
        </module>
        <module name="OneStatementPerLine"/>
        <module name="DeclarationOrder"/>
        <module name="DefaultComesLast"/>
        <module name="VisibilityModifier">
            <property name="protectedAllowed" value="true"/>
        </module>
        <module name="FinalClass"/>
        <module name="InterfaceIsType"/>
        <module name="HideUtilityClassConstructor"/>
        <!--<module name="MutableException"/>-->
        <module name="ThrowsCount">
            <property name="max" value="5"/>
        </module>
        <!--<module name="InnerTypeLast"/> cant find-->

        <!--module name="AvoidStarImport"/-->
        <module name="RedundantImport"/>
        <module name="UnusedImports"/>
        <module name="NeedBraces"/>
        <module name="LineLength">
            <property name="max" value="180"/>
        </module>
        <module name="SimplifyBooleanReturn"/>
        <module name="NestedForDepth">
            <property name="max" value="6"/>
        </module>
        <module name="NestedIfDepth">
            <property name="max" value="4"/>
        </module>
        <module name="NestedTryDepth">
            <property name="max" value="2"/>
        </module>
    </module>
    <module name="FileLength">
        <property name="max" value="1000"/>
    </module>
</module>

config\checkstyle-suppressions.xml

<?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="."
              files="[\\/]target[\\/]"/>
    <suppress files="Application\.java" checks="[a-zA-Z0-9]*"/>
</suppressions>

config\findbugs-exclude.xml

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
    <Match>
        <Package name="~.*\.generated"/>
    </Match>
    <Match>
        <Source name="~.*\.kt"/>
    </Match>
</FindBugsFilter>