【问题标题】:Maven Cobertura plugin not generating coverage.xmlMaven Cobertura 插件不生成coverage.xml
【发布时间】:2012-03-13 00:13:04
【问题描述】:

我正在尝试生成一个coverage.xml,以便我可以在Hudson的Cobertura插件中引用它,但该文件没有被创建。

我已将以下内容添加到我的 POM 中

 <reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
               <formats>
                   <format>html</format>
                   <format>xml</format>
               </formats>
            </configuration>
        </plugin>
    </plugins>
</reporting>

运行 mvn cobertura:cobertura 后,HTML 站点按预期生成在 **\target\site\cobertura,但没有找到coverage.xml。我错过了什么/误解了什么?

我正在运行 Maven 3.0.3

【问题讨论】:

    标签: maven-plugin maven-3 hudson-plugins cobertura


    【解决方案1】:

    对于 Maven 插件和 Hudson 及其插件之间的联系,我还是个新手 - 所以这无论如何都不是一个明智的答案,但对于这个问题,Google 上的帮助很少而且相去甚远 - 所以希望它可以帮助将来的人。

    花了几个小时修改设置后,我发现coverage.xml 似乎根本不是在本地构建的。

    这是使它起作用的组合:

    1. 我在我的 POM 中将我的版本更改为 2.2(我正在获取资源 在 2.5.1 中未发现来自 Apache 的错误)
    2. 在我的 Hudson 目标中添加了 cobertura:cobertura
    3. 将 Cobertura 覆盖模式设置为 推荐 **/target/site/cobertura/coverage.xml

    【讨论】:

      【解决方案2】:

      我将插件放在构建部分,它可以工作:

      <build>
          <plugins>
              <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>cobertura-maven-plugin</artifactId>
                  <version>2.5.1</version>
                  <configuration>
                      <formats>
                          <format>html</format>
                          <format>xml</format>
                      </formats>
                  </configuration>
              </plugin>
          </plugins>
      </build>
      

      报告部分及其与插件部分的差异在here 中进行了描述。我不知道这是 maven [3.0.4] 还是 cobertura-plugin 问题。

      【讨论】:

        【解决方案3】:

        在您的应用程序目标中添加以下行:(在 jenkins 中配置应用程序部分)

        cobertura:cobertura -Dcobertura.report.format=xml
        

        pom.xml 更改:

        <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                </configuration>
            </plugin>
        </plugins>
        

        【讨论】:

        • 请注意,即使 pom 配置同时指定 htmlxml,命令行参数也会覆盖它,指示插件仅生成 xml
        • 感谢 -D 参数
        【解决方案4】:

        我在使用 2.6 的插件时遇到了同样的问题。

        我发现当我指定这两种类型时,我只得到了html。

                   <formats>
                       <format>html</format>
                       <format>xml</format>
                   </formats>
        

        但是当我只指定 xml 时,我得到一个 xml 报告。

                   <formats>
                       <format>xml</format>
                   </formats>
        

        这可能是插件中的一个错误。

        另一位用户建议创建两个执行。我试过没有成功(意思是我得到了 html,但没有 xml)。

        【讨论】:

          【解决方案5】:

          将您的 POM 文件更新为

          <build>
          <plugins>
              <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>cobertura-maven-plugin</artifactId>
                  <version>2.7</version>
                  <configuration>
                      <formats>
                          <format>html</format>
                          <format>xml</format>
                      </formats>
                  </configuration>
              </plugin>
          </plugins>
          

          这对我有用:它包含最新版本的 cobertura-maven-plugin (2.7) 的可能原因

          【讨论】:

            【解决方案6】:

            将 Cobertura 集成到 Maven 中有两种方法。

            1. 将 Cobertura 放入 pom 文件的 build 部分,然后您必须执行 mvn clean cobertura:cobertura 来生成报告。如果您配置了 XML 和 HTML,那么您将获得这两个报告。
            2. 将 Cobertura 放入 pom 文件的 reporting 部分,然后您必须执行 mvn clean site 来生成报告。如果您配置了 XML 和 HTML,那么您将获得这两个报告。此外,您会获得一个生成的站点(打开目标/站点/index.html),其中集成了所有报告,例如Coberture、Checkstyle、...

            【讨论】:

              【解决方案7】:

              我遇到了同样的问题,但现在已经解决了: 只需在您的 maven 命令后添加 -Dcobertura.report.format=xml 即可。它应该工作

              【讨论】:

                【解决方案8】:

                我的目标是让 Cobertura 在mvn test 期间运行而无需额外的命令行参数。这是对我有用的神奇 XML,HTML 和 XML 都是在 /target/site/cobertura 中生成的。

                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>cobertura-maven-plugin</artifactId>
                            <version>2.7</version>
                            <executions>
                                <execution>
                                    <id>cobertura</id>
                                    <phase>test</phase>
                                    <goals>
                                        <goal>cobertura</goal>
                                    </goals>
                                    <configuration>
                                        <formats>
                                            <format>xml</format>
                                            <format>html</format>
                                        </formats>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
                

                【讨论】:

                  猜你喜欢
                  • 2014-03-11
                  • 2014-07-30
                  • 2014-12-01
                  • 2010-11-03
                  • 1970-01-01
                  • 2013-09-14
                  • 2011-07-10
                  • 2013-07-29
                  • 1970-01-01
                  相关资源
                  最近更新 更多