三叶草+ Maven的Eclipse的+

时间:2009-10-19 12:29:24

标签: eclipse maven-2 clover

我正在使用eclipse + maven2来构建我的应用程序。 我需要开始使用三叶草。

因此,我的问题是:根据您的经验,将这些结合起来的最佳方式是什么。

我的意思是,我知道有一个用于eclipse的三叶草插件,还有一个用于maven2的三叶草插件,当然还有用于eclipse的maven插件(m2eclipse - 我已经在使用它)。

我应该使用什么以及如何使用?

谢谢。

2 个答案:

答案 0 :(得分:5)

在Eclipse下,使用Clover Eclipse Plugin

在Maven下,使用Maven Clover Plugin。将Clover Report添加到网站生成:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <configuration>
          [...]
        </configuration>
        <executions>
          <execution>
            <phase>pre-site</phase>
            <goals>
              <goal>instrument</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
  <reporting>
    <plugins>
      [...]
      <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <configuration>
          [...]
        </configuration>
      </plugin>
    </plugins>
  </reporting>
[...]

或者,如果出现违规行为,您可以check for a test coverage百分比并使构建失败:

  <build>
    <plugins>
      <plugin>
        <groupId>com.atlassian.maven.plugins</groupId>
        <artifactId>maven-clover2-plugin</artifactId>
        <configuration>
          <targetPercentage>80%</targetPercentage>
        </configuration>
        <executions>
          <execution>
            <phase>verify</phase>
            <goals>
              <goal>instrument</goal>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

maven build仍然是主人。使用首选方法(命令行或m2eclipse)运行它。

答案 1 :(得分:1)

我正在使用三叶草报告以及maven自动生成的网站。为此,您只需将clover插件添加到您的POM报告部分,如描述here。这样,您还可以获得有关代码覆盖率的历史报告。

调用/启动maven进程是通过m2eclipse插件完成的,就是这样。但你也可以使用所有3个插件。所以例如为eclipse安装clover插件,这样你就不必一次又一次地生成整个站点,只需要代码覆盖(使用eclipse的clover插件就可以在eclipse中看到覆盖范围)并使用用于为任何已发布的代码生成“最终”代码覆盖率的clover maven插件。对于clover-maven和clover-eclipse来说,m2eclipse插件并不是真正需要的,但是在使用eclipse和maven时这很好。