使用 maven 生成 html checkstyle 报告

Generate html checkstyle report with maven

Maven-checkstyle-plugin 包含在编译生命周期中 phase.FailsOneError 配置是 enabled.It 生成 .xml 报告并崩溃 build.I 想要 html 版本使用我的自定义 .xsl 文件 transforming.For 它,我使用 xml-maven-plugin 但我无法将其配置为自动执行并且无法集成到生命周期。

I have to implement this steps:
1)run "mvn install"
2)maven-checkstyle-plugin analyses code
3)plugin finds errors and generates xml report
4)build breaks down
5)xml-maven-plugin automacilly generates .html report

我的一部分pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>${checkstyle.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <goals>
                        <goal>check</goal>
                    </goals>
                    <phase>compile</phase>
                    <configuration>
                        <configLocation>checkstyle/checkstyle.xml</configLocation>
                        <encoding>UTF-8</encoding>
                        <consoleOutput>true</consoleOutput>
                        <failsOnError>false</failsOnError>
                        <includeTestSourceDirectory>false</includeTestSourceDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <version>${xml.maven.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>transform</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <transformationSets>
                    <transformationSet>
                        <dir>target\</dir>
                        <stylesheet>checkstyle\checkstyle-author.xsl</stylesheet>
                        <includes>checkstyle-result.xml</includes>
                        <fileMappers>
                            <fileMapper
                                    implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
                                <pattern>\.xml$</pattern>
                                <replacement>.html</replacement>
                            </fileMapper>
                        </fileMappers>
                    </transformationSet>
                </transformationSets>
            </configuration>
        </plugin>
    </plugins>
</build>

您需要仔细观察阶段和插件。

checkstyle 插件在 "compile" 阶段执行。根据 the docs of the xml-maven-plugin,它的默认阶段是 "generate-resources"。

所以你需要把这个目标放到 a phase 中,晚于 checkstyle 插件(process-类 在编译之后):

<executions>
  <execution>
    <phase>process-classes</phase>
    <goals>
      <goal>transform</goal>
    </goals>
  </execution>
</executions>

我相信 xml 插件的日志应该抱怨丢失的文件,或者如果您 运行 构建两次而没有清理,应该可以工作?这不会是一个好结果。因此,通常最好按顺序执行:)