Currently I'm working on a project that has four components.  We need to know 
the code coverage of just one of those components.  We're using JaCoCo and 
Sonar, but right now the report says we have 0.0% coverage.  My lead says 
that's impossible; he would have expected coverage between 70% and 90%.  I have 
been given the job of finding out why the report is saying 0.0%, and getting it 
to output the right coverage.

I put together a sample project and used JaCoCo to analyze its coverage, and it 
worked just fine.  It generated a "jacoco.xml" file that had a lot of coverage 
information on it.  When I use Maven to run the tests on our actual project, 
that generates a "jacoco.xml" file too, but it's only:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.0//EN" "report.dtd">
<report name="Parent">
  <sessioninfo id="A-1007000-4b0bf47b" start="1389122416273"
               dump="1389122421783"/>
</report>

Policy keeps me from attaching the two actual "pom.xml" files, but at the end 
of this post I list those two "pom.xml" files with everything but the 
JaCoCo-relevant parts stripped out.  I've obviously changed the names of the 
respective components to "Parent" and "Child".  Can anyone tell me why this is 
resulting in the "jacoco.xml" file with no coverage information?

Kevin S

 ##############################################################################

<?xml version="1.0" encoding="UTF-8"?>
<project ...>
  ...
  <name>Parent</name>
  ...
  <profiles>
    <profile>
      <id>create-jacoco-reports</id>
      <activation>
        <property>
          <name>component.pipeline</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.5.10.201208310627</version>
            <configuration>
              <destFile>${project.basedir}/../target/jacoco.exec</destFile>
              <append>true</append>
              <excludes>
                <exclude>**/*Test.*</exclude>
              </excludes>
            </configuration>
            <executions>
              <execution>
                <id>jacoco-intialize</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
              </execution>
              <execution>
                <id>report</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>report</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    ...
  </profiles>
  <build>
    <pluginManagement>
      <plugins>
        ...
        <plugin>
          <groupId>org.jacoco</groupId>
          <artifactId>jacoco-maven-plugin</artifactId>
          <version>${jacoco-maven-plugin.version}</version>
        </plugin>
        ...
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>pre-test</id>
            <goals>
              <goal>prepare-agent</goal>
            </goals>
          </execution>
          <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>report</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

 ##############################################################################

<?xml version="1.0" encoding="UTF-8"?>
<project ...>
  ...
  <name>Child</name>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
      <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
      </plugin>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <reportPlugins>
            ...
            <!-- Code Coverage -->
            <plugin>
              <groupId>org.jacoco</groupId>
              <artifactId>jacoco-maven-plugin</artifactId>
            </plugin>
            ...
          </reportPlugins>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  <reporting>
    <excludeDefaults>true</excludeDefaults>
    <plugins>
      <plugin>
        <!--<groupId>@project.groupId@</groupId>-->
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>@project.version@</version>
      </plugin>
      ...
    </plugins>
  </reporting>
  ...
  <profiles>
    <profile>
      <id>coverage-per-test</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.13</version>
            <configuration>
              <properties>
                <property>
                  <name>listener</name>
                  <value>org.sonar.java.jacoco.JUnitListener</value>
                </property>
              </properties>
            </configuration>
          </plugin>
        </plugins>
      </build>
      <dependencies>
        <dependency>
          <groupId>org.codehaus.sonar-plugins.java</groupId>
          <artifactId>sonar-jacoco-listeners</artifactId>
          <version>1.2</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </profile>
    <profile>
      <id>cr-ja-re</id>
      <activation>
        <property>
          <name>component.pipeline</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.5.10.201208310627</version>
            <configuration>
              <destFile>${project.basedir}/../target/jacoco.exec</destFile>
              <excludes>
                <exclude>**/*Test.*</exclude>
              </excludes>
            </configuration>
            <executions>
              <execution>
                <id>jacoco-intialize</id>
                <goals>
                  <goal>prepare-agent</goal>
                </goals>
              </execution>
              <execution>
                <id>report</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>report</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    ...
  </profiles>
</project>

-- 
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/groups/opt_out.

Reply via email to