在构建中运行mvn checkstyle时构建成功

时间:2019-01-17 11:42:04

标签: maven maven-checkstyle-plugin

我正在将mvn checkstyle作为构建的一部分运行,并已在pom.xml中配置了插件,以使构建失败。 但是,当我运行mvn clean install命令时,构建会成功。 这是pom.xml文件:

<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.demo.test</groupId>
<artifactId>quickstart</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>quickstart</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>     <!-- NOT org.junit here -->
        <artifactId>junit-dep</artifactId>
        <version>4.8.2</version>
    </dependency>
</dependencies>

<build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven 
            defaults (may be moved to parent pom) -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <configLocation>checkstyle.xml</configLocation>
                    <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
                    <consoleOutput>true</consoleOutput>
                    <maxAllowedViolations>2500</maxAllowedViolations>
                    <failsOnError>true</failsOnError>
                    <failOnViolation>true</failOnViolation>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.7.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>3.0.0</version>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>checkstyle</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>

在pom.xml中添加报告部分之后,我运行了mvn site命令,然后在构建中添加了checkstyle插件后,我运行了mvn clean install。但是构建成功了。没有创建checkstyle.xml,没有创建checkstyle-suppressions.xml。这是Java代码。

package com.demo.test.quickstart;

/**
 * Hello world!
 *
 */
public class App 
{
public static void main( String[] args )
{
    System.out.println( "Hello World!" );
}

public static int getNumber10(){
    return 10;
}
}

有人可以帮助我吗?

0 个答案:

没有答案