Maven - 调整报告部分中声明的运行插件的阶段

时间:2011-03-11 17:05:53

标签: maven maven-2 maven-plugin cobertura

我正在尝试调整maven插件执行将在maven-2中运行的阶段。

我的具体问题是尝试运行绑定到生命周期阶段cobertura:instrument的{​​{1}}步骤,以便它不会与使用aspectj的其他插件冲突(并删除检测代码,从而生成覆盖率报告为0%)。但我的问题更为通用。

在deafault生命周期中,我通过在插件声明中添加执行部分来实现这一目标:

process-test-classes

这样,当我运行<build> <plugins> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>instrument-late</id> <phase>process-test-classes</phase> <goals> <goal>instrument</goal> </goals> </execution> </executions> </plugin> ... 一切正常时,cobertura:仪器在我想要的阶段运行,类得到检测,测试运行带有检测类等。这是总结输出:

mvn test

然而,当我[INFO] [clean:clean {execution: default-clean}] [INFO] [buildnumber:create {execution: default}] [INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}] [INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}] [INFO] [resources:resources {execution: default-resources}] [INFO] [compiler:compile {execution: default-compile}] [INFO] [jar:jar {execution: lib}] [INFO] [resources:testResources {execution: default-testResources}] [INFO] Preparing hibernate3:hbm2ddl [WARNING] Removing: hbm2ddl from forked lifecycle, to prevent recursive invocation. [INFO] [buildnumber:create {execution: default}] [INFO] Change the default 'svn' provider implementation to 'javasvn'. [INFO] Checking for local modifications: skipped. [INFO] Updating project files from SCM: skipped. [INFO] Storing buildNumber: 2082 at timestamp: 1299861835678 [INFO] Storing buildScmBranch: trunk [INFO] [native2ascii:native2ascii {execution: native2ascii-utf8}] [INFO] [native2ascii:native2ascii {execution: native2ascii-8859_1}] [INFO] [resources:resources {execution: default-resources}] [INFO] [hibernate3:hbm2ddl {execution: default}] [INFO] [compiler:testCompile {execution: default-testCompile}] [INFO] [jar:test-jar {execution: tests}] [INFO] [dbunit:operation {execution: test-compile}] [INFO] [cobertura:instrument {execution: instrument-late}] [INFO] [surefire:test {execution: default-test}] [INFO] Surefire report directory: /home/carles/dev/ism4web/portasigma/portasigma-web/target/surefire-reports ... Results : Tests run: 62, Failures: 0, Errors: 0, Skipped: 0 Flushing results... Flushing results done Cobertura: Loaded information on 74 classes. Cobertura: Saved information on 74 classes. [INFO] [dbunit:operation {execution: test}] 时,我似乎无法控制插件的执行阶段。我的报告部分包含:

mvn site

<reporting> <plugins> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.4</version> </plugin> (总结)的输出说:

mvn site

仪器被调用两次,一个在插件定义的(我假定的)默认阶段,另一个在我重新定义的阶段。我想这来自于在网站生命周期中运行的插件。

问题: 我还没有找到如何在报告部分/站点生命周期内调整插件执行。任何提示?

2 个答案:

答案 0 :(得分:1)

我在这里猜测,但我认为正在发生的事情是因为cobertura目标在其自己的生命周期中运行,所以检测步骤被调用两次,一次来自maven生命周期,一次来自cobertura生命周期。

答案 1 :(得分:0)

经过与Cobertura的多次尝试后,我切换到JaCoCo - 即时检测仪器和恢复检测类的选项。

虽然我没有尝试过你提议的 cobertura-it

只需添加插件旁边的配置:

<executions>
  <execution>
    <id>jacoco-initialize</id>
    <phase>initialize</phase> <!-- m2e complains if you skip, though mine complains on this either, had to mark it as ignored by m2e, feel free to omit the phase, defaults are fine -->
    <goals>
      <goal>prepare-agent</goal>
    </goals>
  </execution>
  <execution>
    <id>jacoco-site</id>
    <phase>package</phase>
    <goals>
      <goal>report</goal>
    </goals>
  </execution>
</executions>

对我来说,额外的好处是我不再遇到Java 1.7问题。

编辑:更改了jacoco-initialize的阶段,之前的版本错误:在mvn clean之后它不再创建jacoco.exec文件,从而导致无覆盖报告。