【问题标题】:Generate html checkstyle report with maven使用 maven 生成 html checkstyle 报告
【发布时间】:2017-12-28 15:32:58
【问题描述】:

Maven-checkstyle-plugin 包含在编译阶段的生命周期中。FailsOneError 配置已启用。它会生成 .xml 报告并使构建崩溃。我想使用我的自定义 .xsl 文件获取 html 版本进行转换。为此,我使用 xml-maven-plugin 但我无法将其配置为自动执行,也无法集成到生命周期中。

我必须执行以下步骤:
1) 运行“mvn install”
2)maven-checkstyle-plugin 分析代码
3)插件发现错误并生成xml报告
4) 构建崩溃
5)xml-maven-plugin 自动生成.html 报告

我的 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>

【问题讨论】:

    标签: xml maven xslt maven-plugin checkstyle


    【解决方案1】:

    您需要密切关注阶段和插件。

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

    所以你需要在 checkstyle 插件之后将这个目标放入a phase(进程类在编译之后):

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

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

    【讨论】:

      猜你喜欢
      • 2015-07-12
      • 1970-01-01
      • 2021-10-10
      • 2021-10-31
      • 2013-07-23
      • 1970-01-01
      • 1970-01-01
      • 2014-05-15
      • 1970-01-01
      相关资源
      最近更新 更多