Maven Checkstyle:Check not working

前端 未结 3 1639
再見小時候
再見小時候 2021-01-18 19:31

I have been working on trying to get Checkstyle working in Maven in the Eclipse Indigo IDE for a while. Finally, I thought I will ask for some expert advise on this.

相关标签:
3条回答
  • 2021-01-18 20:06

    googe_checks.xml has to be located in your project where pom.xml is present. mvn checkstyle:check

    <properties>
        <checkstyle.config.location>google_checks.xml</checkstyle.config.location>
        <checkstyle.violationSeverity>warning</checkstyle.violationSeverity>
        <checkstyle.consoleOutput>true</checkstyle.consoleOutput>
    </properties>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <version>3.0.0</version>
                    <dependencies>
                        <dependency>
                            <groupId>com.puppycrawl.tools</groupId>
                            <artifactId>checkstyle</artifactId>
                            <version>8.8</version>
                        </dependency>
                    </dependencies>
                    <executions>
                        <execution>
                            <id>validate</id>
                            <phase>validate</phase>`
                            <properties>
                                <checkstyle.config.location>google_checks.xml</checkstyle.config.location>
                                <checkstyle.violationSeverity>warning</checkstyle.violationSeverity>
                                <checkstyle.consoleOutput>true</checkstyle.consoleOutput>
                            </properties>
    
                            <build>
                                <pluginManagement>
                                    <plugins>
                                        <plugin>
                                            <groupId>org.apache.maven.plugins</groupId>
                                            <artifactId>maven-checkstyle-plugin</artifactId>
                                            <version>3.0.0</version>
                                            <dependencies>
                                                <dependency>
                                                    <groupId>com.puppycrawl.tools</groupId>
                                                    <artifactId>checkstyle</artifactId>
                                                    <version>8.8</version>
                                                </dependency>
                                            </dependencies>
                                            <executions>
                                                <execution>
                                                    <id>validate</id>
                                                    <phase>validate</phase>
                                                    <goals>
                                                        <goal>check</goal>
                                                    </goals>
                                                </execution>
                                            </executions>
                                        </plugin>
                                    </plugins>
                                </pluginManagement>
                            </build>
                            </project>
                            `
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    </project>
    
    0 讨论(0)
  • 2021-01-18 20:16

    1.configLocation for a custom checkstyle is being ignored and always default to Sun checkstyle.

    For this please use below tag:

    <properties<checkstyle.config.location>properties/checkstyle.xml</checkstyle.config.location>  </properties>
    

    in your POM.xml of project on which your using checkstyle.this line will be on the top and below tag of pom.xml.

    <version>0.0.1-SNAPSHOT</version>
    
    0 讨论(0)
  • 2021-01-18 20:28

    You have bound check goal of maven checkstyle plugin to compile phase. That being the case, you would need to run mvn compile for your configurations to be used. Running mvn checkstyle:check will use default configurations. This looks like the most likely case for items 1 and 2 above.

    Even if you were to run mvn compile the above configuration will still fail the build on account of the two configuration entries failOnViolation and failOnError since both of them are set to true. Removing these entries and running mvn compile should pass the build so long as the number of violations are less than 7000.

    0 讨论(0)
提交回复
热议问题