use of build-helper-maven-plugin and multi module skip the test - maven

I use the build-helper-maven-plugin for a legacy project with a non standard tree folder.
I use it this way :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/firstmodule/src</source>
<source>${basedir}/secondmodule/src</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/firstmodule/tests</source>
<source>${basedir}/secondmodule/tests</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
It works correctly if I launch mvn install on the root of the project, tests passed.
However, this project is a submodule in a bigger project.
If I launch mvn install in the root folder of the parent project, maven don't execute the test.
it seems to work but surefire do not detect any test :
[INFO] Building MyLegacyProject
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\target
[INFO] [build-helper:add-source {execution: add-source}]
[INFO] Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\firstmodule\src added.
[INFO] Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\secondmodule\src added.
[INFO] [build-helper:add-test-source {execution: add-test-source}]
[INFO] Test Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\firstmodule\tests added.
[INFO] Test Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\secondmodule\tests added.
[debug] execute contextualize
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 40 resources
[INFO] Copying 40 resources
[WARNING] While downloading com.sun.xml:saaj-impl:1.3
This artifact has been relocated to com.sun.xml.messaging.saaj:saaj-impl:1.3.
[WARNING] While downloading javax.xml:jaxb-api:2.1
This artifact has been relocated to javax.xml.bind:jaxb-api:2.1.
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 752 source files to C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\target\classes
[debug] execute contextualize
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 34 resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 15 source files to C:\DEV\perforce\1992\depot\MyLegacyProject\release\BUG_FIXING\MyLegacyProject\target\test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\DEV\perforce\1992\depot\MyLegacyProject\release\BUG_FIXING\MyLegacyProject\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.381 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
any idea how to made this work ?

Try to launch mvn with the debug mode (-X) to view if properties used by surefire are correct for your tree folder.

Are you using Maven 3 ? ${basedir} is recognized only by maven 3 (and silently ignored by maven 2 :( )
How do you understand the basedir usage ? It is the directory path of the POM where the build started. Thus it will be either the path to the parent project directory or one of its modules depending where you are launching the build from. In the second case the path will be wrong. I suppose you expected to have always the path to the root directory of your project ?

Ok I found it !!!
Somebody had the same problem :
https://stackoverflow.com/a/6925096/242658
However it was really hard to figure it.
It was not related to build-helper-maven-plugin and I don't know why I had not this problem in single module mode.
I used powermock and powermock that pulled in TestNG. And with testng my tests are not detected by surefire. So I had to exclude testng:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-mockito-release-full</artifactId>
<version>1.4.9</version>
<classifier>full</classifier>
<exclusions>
<exclusion>
<artifactId>powermock-module-testng</artifactId>
<groupId>org.powermock</groupId>
</exclusion>
</exclusions>
</dependency>

Related

maven-compiler-plugin: change <outputDirectory> per execution

situation
I have XML files which I need to deal with in my GUI (JavaXF) and in my JavaStoredProcedures in my oracle12c database.
In the GUI I want to use properties bindings.
So I configured the maven-jaxb2-plugin to generate the sources with properties.
The database on the other hand does not support Java8 therefore is configured a second execution for the maven-jaxb2-plugin to generate the sources without properties in a different folder ending up with two folders containing the same Java-classes in the same packages in different folders.
So what I have now looks like this:
project
\-target
\-generated-sources
+-java7
| \-package.with.java.files
| \-Java7-compilabe-sources*
\-java8
\-package.with.java.files
\-Java8-compilabe-sources*
What I want to do next is to compile the two folders target/generated-sources/java7 and target/generated-sources/java8 to different output folders target/java7/classes and target/java8/classes respectively within different executions of the maven-compiler-plugin.
But I'm not able to change the output directory of the maven-compiler-plugin for a single execution.
This is my current configuration of the maven-compiler-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<encoding>ISO-8859-1</encoding>
</configuration>
<executions>
<execution>
<id>java8</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<executable>${jdk-1.8}/bin/javac</executable>
<compilerVersion>1.8</compilerVersion>
<sourceDirectory>${project.build.directory}/generated-sources/java8</sourceDirectory>
<outputDirectory>${basedir}/target/java8/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
But from the maven output it looks like it does not respect either one of <sourceDirectory> nor <outputDirectory>:
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject 6.0.5
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # MyProject ---
[INFO] Deleting /ProjectRoot/target
[INFO]
[INFO] --- maven-jaxb2-plugin:0.13.1:generate (Java8) # MyProject ---
[INFO] Up-to-date check for source resources [[file:/ProjectRoot/src/main/xsd/parad.xsd, file:/ProjectRoot/src/main/xjb/bindings.xml, file:/ProjectRoot/pom.xml]] and target resources [[]].
[INFO] Sources are not up-to-date, XJC will be executed.
[INFO] Episode file [/ProjectRoot/target\generated-sources\java8\META-INF\sun-jaxb.episode] was augmented with if-exists="true" attributes.
[INFO]
[INFO] --- maven-jaxb2-plugin:0.13.1:generate (Java7) # MyProject ---
[INFO] Up-to-date check for source resources [[file:/ProjectRoot/src/main/xsd/parad.xsd, file:/ProjectRoot/src/main/xjb/bindings.xml, file:/ProjectRoot/pom.xml]] and target resources [[]].
[INFO] Sources are not up-to-date, XJC will be executed.
[INFO] Episode file [/ProjectRoot/target\generated-sources\java7\META-INF\sun-jaxb.episode] was augmented with if-exists="true" attributes.
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # MyProject ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # MyProject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 114 source files to /ProjectRoot/target\classes
findings
the compiler pluging does not show the execution ID (as the maven-jaxb2-plugin does)
the compiler pluging compiles both target/generated-sources/java7 and target/generated-sources/java8 (each contains 57 *.java files) although <sourceDirectory> is given in execution/config
the compiler pluging compiles to target/classes although <outputDirectory> is given in execution/config
question
how do I force maven to compile each of target/generated-sources/java7 and target/generated-sources/java8 to its own target folder separately?
additional info
$ mvn --version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T13:57:37+02:00)
I solved the problem by usting the maven-antrun-plugin.
first I turend off compilation by excluding all files:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<encoding>ISO-8859-1</encoding>
<source>1.8</source>
<target>1.8</target>
<executable>${jdk-1.8}/bin/javac</executable>
<compilerVersion>1.8</compilerVersion>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
I also turned of the maven-jar-plugin
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>default-jar</id>
<phase>never</phase>
<configuration>
<finalName>unwanted</finalName>
<classifier>unwanted</classifier>
</configuration>
</execution>
</executions>
then I configured separate executions in the maven-antrun-plugin to compile eache source folder and create the separate jars.
what's left is to configure the maven-deploy-plugin so that the two jars (and their source jars) are correctly placed in the maven repository so that they can be fetched as dependencies.

2 exec-maven-plugin defined in POM - not working

I have two Java main classes that I need executed during different parts of a build process. One needs to execute ALWAYS as part of my standard build process during the generate-sources phase. The other needs to execute as part of a profile, but that profile should be execute at the end of the process-classes phase, which should also include the generate-sources phase prior to that.
I was able to get the first plugin working correctly during the generate-sources phase of the standard build process:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.MySourceGenerator</mainClass>
</configuration>
</plugin>
However when I added a second instance of the same plugin to the profile, the plugin defined as part of the standard build is no longer invoked during my build process, resulting in compile errors. This is the configuration in the profile:
<profiles>
<profile>
<id>initSchema</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.example.SomeOtherClass</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
This is what I run on the command line: mvn process-classes -PinitSchema. What is wrong with my configuration? I am expecting both plugins to execute during their respective phases.
To clarify: the first exec-maven-plugin generates sources and the second one initialized my DB schema.
EDIT:
Here is the output
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ABC Web Application 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) # web-app ---
[INFO] Source directory: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/generated-sources/msg added.
[INFO]
[INFO] --- maven-processor-plugin:2.0.6:process (process) # web-app ---
[INFO] Source directory: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/generated-sources/apt added
[INFO] javac option: -cp
...
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: com.company.vocab.generator.VocabAnnotationProcessor,org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor
[INFO] javac option: -d
[INFO] javac option: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/classes
[INFO] javac option: -s
[INFO] javac option: /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/generated-sources/apt
[INFO] diagnostic Note: Hibernate JPA 2 Static-Metamodel Generator 1.2.0.Final
[INFO] diagnostic /Users/wendyschmitz/projects/ae/abc-proj/web-app/src/main/java/com/company/service/dto/AccountDto.java:5: error: cannot find symbol
import com.telos.xacta.util.Messages;
...
(more similar messages)
[INFO]
[INFO] --- jaxb2-maven-plugin:1.5:xjc (default) # web-app ---
[INFO] Generating source...
[INFO] parsing a schema...
[INFO] compiling a schema...
...
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # web-app ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 16 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # web-app ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 281 source files to /Users/wendyschmitz/projects/ae/abc-proj/web-app/target/classes
[INFO] -------------------------------------------------------------
...
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/wendyschmitz/projects/ae/abc-proj/web-app/src/main/java/com/company/service/dto/ProjectHeadDto.java:[4,28] cannot find symbol
symbol: class Messages
location: package com.company.util
...
(more similar errors)
...
[INFO] 29 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.817s
[INFO] Finished at: Thu Aug 01 20:49:07 EDT 2013
[INFO] Final Memory: 31M/282M
[INFO] ------------------------------------------------------------------------
Give both the execution blocks a different id, because now they both use the default id and so one will overwrite the other.

How can I specify an ant target to run during the release:prepare goal?

When using the maven release plugin I want to do some pre-work (via an ant tast) as part of the release build with the assurance that the same code base is used (so no commits sneak in between). I have an ant task that I want to call to do this, but I'm having the following issue:
inside my pom file:
<configuration>
<preparationGoals>antrun:run -Dtarget=${antTaskJarBuildXML} clean verify</preparationGoals>
</configuration>
where ${antTaskJarBuildXML} is:
<target><ant antfile=\"../build.xml\" target=\"iv_dependency_build\" /></target>
When I run release:perform this is the log:
...
[INFO] Not generating release POMs
[INFO] Executing goals 'antrun:run -Dtarget="<target><ant antfile=\"../build.xml\" target=\"iv_dependency_build\" /></target>" clean verify'...
[WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance.
[INFO] [INFO] Scanning for projects...
[INFO] [WARNING]
[INFO] [WARNING] Some problems were encountered while building the effective model for com.xactsites:iv:war:12.12.4.9
[INFO] [WARNING] The expression ${version} is deprecated. Please use ${project.version} instead.
[INFO] [WARNING]
[INFO] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[INFO] [WARNING]
[INFO] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[INFO] [WARNING]
[INFO] [INFO]
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Building iv 12.12.4.9
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [WARNING] The artifact javax.xml:jaxrpc:jar:1.1 has been relocated to javax.xml:jaxrpc-api:jar:1.1
[INFO] [INFO]
[INFO] [INFO] --- maven-antrun-plugin:1.7:run (default-cli) # iv ---
[INFO] [INFO] No ant target defined - SKIPPED
[INFO] [INFO]
[INFO] [INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) # iv ---
[INFO] [INFO] Deleting C:\dev\apps\iv\target
[INFO] [INFO]
...
And as shown in the log, I am told that no target is specified. I followed what I understood from the ant run documentation
Am I missing something in how to pass in the target name?
Is this the best approach?
Is it a matter of escaping that I am missing? I'm on windows and this is the actual value defined for the xml (${antTaskJarBuildXML}):
"<target><ant antfile=\"../build.xml\" target=\"iv_dependency_build\" /></target>"
EDIT
#carlspring has given some great feedback (+1 on his answer), however, due to the nature of the problem where not everything is mavenized I couldn't get this working. Maven is expecting to be in control of the whole release process, but I need to perform an ant task (which creates dependencies needed for the build in question) beforehand. I also need to be assured that this prework task and the regular build are built against the same git tag/hash. My current solution is to sequentially do the steps that the release plugin would perform as discussed here. Through this I can create a git tag then do the maven build against that same git tag. If there are any better ideas out there please contribute!
My suggestions would be for you to define a profile and have your ant-run definition in it.
The release plugin forks, meaning your command-line args will be ignored.
UPDATE:
Try this:
<?xml version="1.0" encoding="UTF-8"?>
<project ...>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>execute-prepare</id>
<!-- Set up your Ant stuff here -->
<goals>
<goal>prepare</goal>
</goals>
<configuration>
<!-- If you have args specific for your release, put them here: -->
<arguments>-Pant-run-release</arguments>
<releaseProfiles>ant-run-release</releaseProfiles>
<mavenExecutorId>forked-path</mavenExecutorId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>ant-run-release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>execute-something</id>
<!-- Set up your Ant stuff here -->
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

How to run testNG tests using Maven POM file

I have a Selenium project, using Maven and TestNG.
I have tried several different methods of getting my tests to run with a Maven command (I'm using the sure fire plugin).
When I run Maven the tests do not run. There are no errors.
Has anyone got a good example or a tutorial that I could follow to get my test to run when I use mvn test?
Thanks in advance.
Here is the output:
C:\**************>mvn test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - **************:**************:jar:1.0
[INFO] task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\**************\src\test\res
ources
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Oct 02 15:14:10 BST 2012
[INFO] Final Memory: 16M/38M
[INFO] ------------------------------------------------------------------------
And the surefire configuration from my POM file:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>iso-8859-1</encoding>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/main/test_suites/local/***_Test.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Take a look at this Maven Using TestNG site.
Basically all you have to do is adding a dependency to the TestNG.
<dependencies>
[...]
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
<scope>test</scope>
</dependency>
[...]
</dependencies>
The default includes in maven-surefire-plugin are:
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
That means that if the name of your test classes does not match the above include patterns then maven-surefire-plugin will not find them and run them.
You can change/add files to include by adding these to the plugin configuration.

Maven - Tweaking the phase where to run a plugin declared in the reporting section

I am trying to tweak the phase when a maven plugin execution will run in maven-2.
My specific issue is with attempting to run the cobertura:instrument step bound to the lifecycle phase process-test-classes, so that it doesn't conflict with other plugins that use aspectj (and remove instrumentation code, thus generating a coverage report of 0%). But my question is more generic.
Within the deafault lifecycle, I have managed to do that by adding an executions section in 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>
...
This way, when I run mvn test everything works fine, cobertura:instrument is run at the phase I want, classes get instrumented, tests run with instrumented classes, etc. This is summarized output:
[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 mvn site I seem to have no control over the execution phase for the plugin. My reporting 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 (summarized) 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.
Instrument is called twice, one at the (I presume) default phase defined by the plugin, and another one at my redefined phase. I guess that comes from the plugin running during as part of the site lifecycle.
THE QUESTION:
I haven't found how to tweak the plugin execution within the reporting section / site lifecycle. Any hints?
I'm guessing here but I think what is happening is that because the cobertura goal runs in its own lifecycle the instrumentation step is called twice, once from the maven lifecycle and once from the cobertura lifecycle.
After number of tries with Cobertura I switched to JaCoCo - instrumentation on the fly and option of restoring instrumented classes.
Though I have not tried your proposed cobertura-it.
Only config required beside adding the plugin:
<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>
Additional bonus for me is that I had no longer issues with Java 1.7.
EDIT: changed phase for jacoco-initialize, previous version was wrong: after mvn clean it no longer would create jacoco.exec file thus resulting in no coverage reports.

Resources