Maven - setting up the plugin launch phase declared in the reports section

I am trying to adjust the phase when the execution of the maven plugin will be executed in maven-2.

My particular problem is trying to execute the cobertura:instrument step at the process-test-classes lifecycle stage so that it does not conflict with other plugins using aspectj (and removes the instrumentation code, thereby generating a coverage report of 0%). But my question is more general.

Inside the deafault lifecycle, I managed to do this by adding a runtime section to my plugin declaration:

 <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> ... 

Thus, when I run mvn test , everything works fine, cobertura: the tool runs in the phase I want, the classes get the tools, the tests run with the tool classes, etc. This is a generalized result:

 [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}] 

However, when I do the mvn site , I don't seem to control the execution phase for the plugin. The reports section contains:

 <reporting> <plugins> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.4</version> </plugin> 

And the output of mvn site (generic) says:

 [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] [cobertura:instrument {execution: default-instrument}] [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] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Unable to prepare instrumentation directory. Embedded error: source and destination are the same directory. 

The tool is called twice, one in the default phase (I assume) defined by the plugin, and the other in my overridden phase. I assume this comes from a plugin that runs as part of the site's life cycle.

QUESTION: I did not find how to configure the plugin within the report / life cycle section of the site. Any clues?

+7
source share
2 answers

I assume that here, but I think that what happens is because the cobertura goal is executed in its own life cycle, the instrumentation step is called twice, once from the maven life cycle and once from the cobertura life cycle.

+1
source

After several attempts with Cobertura, I switched to JaCoCo - on the fly, and the ability to restore tool classes.

Although I have not tried to offer cobertura-it .

To add a plugin, only the configuration is required:

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

An added bonus for me is that I no longer quit Java 1.7.

EDIT: the changed phase for jacoco-initialize, the previous version was wrong: after mvn clean it will no longer create the jacoco.exec file, which will not result in no coverage reports.

0
source

All Articles