Не получается настроить maven checkstyle

132
23 января 2022, 13:50
    <?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.site</groupId>
    <artifactId>Project</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.9</source>
                    <target>1.9</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>validate</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <phase>validate</phase>
                        <configuration>
                            <configLocation>src/main/resources/checkstyle.xml</configLocation>
                            <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
                            <encoding>UTF-8</encoding>
                            <failOnViolation>true</failOnViolation>
                            <violationSeverity>warning</violationSeverity>
                            <includeTestSourceDirectory>false</includeTestSourceDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Это pom файл

Файл checkstyle.xml

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
        "https://checkstyle.org/dtds/configuration_1_3.dtd">
<!--
  Checkstyle configuration that checks the sun coding conventions from:
    - the Java Language Specification at
      https://docs.oracle.com/javase/specs/jls/se11/html/index.html
    - the Sun Code Conventions at https://www.oracle.com/technetwork/java/codeconvtoc-136057.html
    - the Javadoc guidelines at
      https://www.oracle.com/technetwork/java/javase/documentation/index-137868.html
    - the JDK Api documentation https://docs.oracle.com/en/java/javase/11/
    - some best practices
  Checkstyle is very configurable. Be sure to read the documentation at
  http://checkstyle.sourceforge.net (or in your downloaded distribution).
  Most Checks are configurable, be sure to consult the documentation.
  To completely disable a check, just comment it out or delete it from the file.
  Finally, it is worth reading the documentation.
-->
<module name="Checker">
    <!--
        If you set the basedir property below, then all reported file
        names will be relative to the specified directory. See
        https://checkstyle.org/5.x/config.html#Checker
        <property name="basedir" value="${basedir}"/>
    -->
    <property name="fileExtensions" value="java, properties, xml"/>
    <!-- Excludes all 'module-info.java' files              -->
    <!-- See https://checkstyle.org/config_filefilters.html -->
    <module name="BeforeExecutionExclusionFileFilter">
        <property name="fileNamePattern" value="module\-info\.java$"/>
    </module>
    <!-- Checks whether files end with a new line.                        -->
    <!-- See http://checkstyle.sourceforge.net/config_misc.html#NewlineAtEndOfFile -->
    <module name="NewlineAtEndOfFile"/>
    <!-- Checks that property files contain the same keys.         -->
    <!-- See http://checkstyle.sourceforge.net/config_misc.html#Translation -->
    <module name="Translation"/>
    <!-- Checks for Size Violations.                    -->
    <!-- See http://checkstyle.sourceforge.net/config_sizes.html -->
    <module name="FileLength"/>
    <!-- Checks for whitespace                               -->
    <!-- See http://checkstyle.sourceforge.net/config_whitespace.html -->
    <module name="FileTabCharacter"/>
    <!-- Miscellaneous other checks.                   -->
    <!-- See http://checkstyle.sourceforge.net/config_misc.html -->
    <module name="RegexpSingleline">
        <property name="format" value="\s+$"/>
        <property name="minimum" value="0"/>
        <property name="maximum" value="0"/>
        <property name="message" value="Line has trailing spaces."/>
    </module>
    <!-- Checks for Headers                                -->
    <!-- See http://checkstyle.sourceforge.net/config_header.html   -->
    <!-- <module name="Header"> -->
    <!--   <property name="headerFile" value="${checkstyle.header.file}"/> -->
    <!--   <property name="fileExtensions" value="java"/> -->
    <!-- </module> -->
    <module name="TreeWalker">
        <!-- Checks for Naming Conventions.                  -->
        <!-- See http://checkstyle.sourceforge.net/config_naming.html -->
        <module name="ConstantName"/>
        <module name="LocalFinalVariableName"/>
        <module name="LocalVariableName"/>
        <module name="MemberName"/>
        <module name="MethodName"/>
        <module name="PackageName"/>
        <module name="ParameterName"/>
        <module name="StaticVariableName"/>
        <module name="TypeName"/>
        <!-- Checks for imports                              -->
        <!-- See http://checkstyle.sourceforge.net/config_import.html -->
        <module name="AvoidStarImport"/>
        <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
        <module name="RedundantImport"/>
        <module name="UnusedImports">
            <property name="processJavadoc" value="false"/>
        </module>
        <!-- Checks for Size Violations.                    -->
        <!-- See http://checkstyle.sourceforge.net/config_sizes.html -->
        <module name="LineLength"/>
        <module name="MethodLength"/>
        <module name="ParameterNumber"/>
        <!-- Checks for whitespace                               -->
        <!-- See http://checkstyle.sourceforge.net/config_whitespace.html -->
        <module name="EmptyForIteratorPad"/>
        <module name="GenericWhitespace"/>
        <module name="MethodParamPad"/>
        <module name="NoWhitespaceAfter"/>
        <module name="NoWhitespaceBefore"/>
        <module name="OperatorWrap"/>
        <module name="ParenPad"/>
        <module name="TypecastParenPad"/>
        <module name="WhitespaceAfter"/>
        <module name="WhitespaceAround"/>
        <!-- Modifier Checks                                    -->
        <!-- See http://checkstyle.sourceforge.net/config_modifiers.html -->
        <module name="ModifierOrder"/>
        <module name="RedundantModifier"/>
        <!-- Checks for blocks. You know, those {}'s         -->
        <!-- See http://checkstyle.sourceforge.net/config_blocks.html -->
        <module name="AvoidNestedBlocks"/>
        <module name="EmptyBlock"/>
        <module name="LeftCurly"/>
        <module name="NeedBraces"/>
        <module name="RightCurly"/>
        <!-- Checks for common coding problems               -->
        <!-- See http://checkstyle.sourceforge.net/config_coding.html -->
        <module name="EmptyStatement"/>
        <module name="EqualsHashCode"/>
        <module name="HiddenField"/>
        <module name="IllegalInstantiation"/>
        <module name="InnerAssignment"/>
        <module name="MagicNumber"/>
        <module name="MissingSwitchDefault"/>
        <module name="SimplifyBooleanExpression"/>
        <module name="SimplifyBooleanReturn"/>
        <!-- Checks for class design                         -->
        <!-- See http://checkstyle.sourceforge.net/config_design.html -->
        <module name="DesignForExtension"/>
        <module name="FinalClass"/>
        <module name="HideUtilityClassConstructor"/>
        <module name="InterfaceIsType"/>
        <module name="VisibilityModifier"/>
        <!-- Miscellaneous other checks.                   -->
        <!-- See http://checkstyle.sourceforge.net/config_misc.html -->
        <module name="ArrayTypeStyle"/>
        <module name="FinalParameters"/>
        <module name="TodoComment"/>
        <module name="UpperEll"/>
    </module>
</module>

файл checkstyle-suppressions.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
    The MIT License
    Copyright © 2014-2019 Ilkka Seppälä
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
-->
<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN"
    "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
   <suppress checks="AvoidStarImport" files="[\\/]src[\\/]test[\\/]java[\\/]"/>
   <suppress checks="[a-zA-Z0-9]*" files="[\\/]src[\\/]test[\\/]resources[\\/]"/>
   <suppress checks="[a-zA-Z0-9]*" files="[\\/]build[\\/]generated-sources[\\/]"/>
   <suppress checks="[a-zA-Z0-9]*" files="[\\/]src[\\/]main[\\/]resources[\\/]"/>
</suppressions>

Так вот при запуске checkstyle:check игнорируется мой файл checkstyle.xml и в target генерируется checkstyle-checker.xml на основании которого и ведётся проверка. Подскажите как исправить, чтобы проверка была согласно моему файлу checkstyle.xml

Answer 1

Код рабочий. Типичная ошибка в английских буквах похожих на русские. Проблема была в слове checkstyle

READ ALSO
Как разметить данный блок?

Как разметить данный блок?

Как разметить блок, чтобы выстроить элементы в линию?

136
Не работает опция shedule

Не работает опция shedule

С чем может быть связано нежелание g++ компилировать OpenMP программу с использованной опцией shedule(dynamic)?

76
Освобождение массива double-ов в std::unique_ptr

Освобождение массива double-ов в std::unique_ptr

Нужен массив double-овКоличество элементов определяется только во время выполнения программы - поэтому в стеке создать не получится

91
Как обрабатывать заголовок Keep-Alive?

Как обрабатывать заголовок Keep-Alive?

Пишу свой http-сервер, для обработки запросов использую классическую схемy: на каждый запрос устанавливается отдельное соединение в отдельном...

170