Hi Christian,
the JaCoCo Maven plugin does not yet support different aspects of multi
module projects. The current implementation assumes that the code under
test and the tests itself are in the same module.
The issue you encounter is that the report is created within the test
module but it can't find the classes under test here.
A possible workaround is to use the Ant plug-in and create the report
with JaCoCo's Ant tasks. This is how the coverage report for JaCoCo
itself is created:
https://github.com/jacoco/jacoco/blob/master/org.jacoco.doc/pom.xml#L76
Best regards,
-marc
On 2014-09-09 09:21, [email protected] wrote:
I'm currently working as a student employee for a company. My task is
to implement test coverage into their multi-module-project.
I'm pretty new to the subject matter so please keep that in mind while
answering.
We are using the OSGi specification and Maven 3.2.3. The build is
called with `mvn clean install`. The project is written in Java.
I implemented the Jacoco Maven plugin as you can see below.
<!-- implementing jacoco plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.5.201112152213</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
The build runs successfuly but JaCoCo is not creating the needed
coverage reports.
The only reports I get are from the tests itself. The classes we want
to test appear within the session.html but aren't linked.
I already found out that this can happen if classes get modified
during the build process, so I implemented an ant task to instrument
the classes seperately. But it is still not working.
I currently don't know how to tell JaCoCo to use the
pre-instrumented-classes for creating the jacoco.exec. Furthermore
after building the project there is not in every module a jacoco.exec
even if it's supposed to be there.
Our Structur looks like this just with way more modules:
multi-module-failing-example
|-- build
| |--pom
| |--(parent-pom-module.xml)
| |--(parent-pom-module2.xml)
| `--root-pom.xml
|-- Module
| |--product
| | |-- pom.xml
| | `-- src
| | `-- main
| | `-- java
| | `-- Calculator.java
| |--product2
| | |-- pom.xml
| | `-- src
| | `-- main
| | `-- java
| | `-- Calculator2.java
| |-- test
| | |-- pom.xml
| | `-- src
| | `-- test
| | `--java
| | `-- CalculatorTest.java
| `-- test2
| |-- pom.xml
| `-- src
| `-- test
| `-- java
| `-- CalculatorTest2.java
`-- Module2
|--product3
| |-- pom.xml
| `-- src
| `-- main
| `-- java
| `-- Calculator3.java
|--product4
| |-- pom.xml
| `-- src
| `-- main
| `-- java
| `-- Calculator4.java
|-- test3
| |-- pom.xml
| `-- src
| `-- test
| `--java
| `-- CalculatorTest3.java
`-- test4
|-- pom.xml
`-- src
`-- test
`-- java
`-- CalculatorTest4.java
Whole root pom:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!--
POM defining the build process (maven pluins and their
configuration, repositories, ...).
Needs to be referenced as parent from all other POMs (directly or
indirectly)
-->
<modelVersion>4.0.0</modelVersion>
<groupId>multi.module.project</groupId>
<artifactId>root</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<tycho-version>0.19.0</tycho-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<!-- enable tycho build extension -->
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<ignoreTychoRepositories>true</ignoreTychoRepositories>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
</environments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<optimize>true</optimize>
</configuration>
<executions>
<execution>
<id>groovy</id>
<goals>
<goal>compile</goal>
</goals>
<phase>compile</phase>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.7.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.1.1-01</version>
<!-- <version>1.7.10-06</version>
-->
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<argLine>${argLine} -XX:MaxPermSize=256M
-Xmx1024M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=c:/temp
-Dcom.sun.management.jmxremote </argLine>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>JUnitTest</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<includes>
<include>**/AllTests.java</include>
<include>**/_AllTests.java</include>
</includes>
<testSourceDirectory>src</testSourceDirectory>
<testClassesDirectory>target/classes</testClassesDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- implementing jacoco plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.5.5.201112152213</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<!-- Ant task to instrument classes-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<ant antfile="build.xml">
<target name="startInstrument"/>
</ant>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>juno</id>
<layout>p2</layout>
<url>${eclipse-repo}</url>
</repository>
<repository>
<id>orbit</id>
<layout>p2</layout>
<url>${orbit-repo}</url>
</repository>
<repository>
<id>help</id>
<layout>p2</layout>
<url>${oh-repo}</url>
</repository>
</repositories>
</project>
I already tried the JaCoCo configurations with a way smaller project
and it's working fine.
Could there be a problem with the OSGi structure?
How can I tell JaCoCo to create coverage reports from the
pre-instrumented classes?
Could this problem be linked to our use of tycho?
Best regards
Christian
--
You received this message because you are subscribed to the Google Groups "JaCoCo
and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.