Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-15570

Coverage report includes classes that have been excluded from Jacoco analysis

      In my Maven config there are a number of classes that are excluded from Jacoco analysis. The report generated by Jacoco does not include these classes. The report generated by the Jenkins Jacoco plugin does includes these classes which gives a misleading picture and makes it difficult to set any coverage thresholds. I think this may be related to JENKINS-14975.

          [JENKINS-15570] Coverage report includes classes that have been excluded from Jacoco analysis

          Darrell King created issue -

          Ognjen Bubalo added a comment -

          Hi,

          Please give us more information.

          Which plugin version do you use?
          What is your current configuration on the configuration page of JaCoCo plugin?

          Cheers,
          Ogi

          Ognjen Bubalo added a comment - Hi, Please give us more information. Which plugin version do you use? What is your current configuration on the configuration page of JaCoCo plugin? Cheers, Ogi

          Rune Flobakk added a comment -

          I am guessing this is related to classes which are generated, e.g. from WSDLs. A common use case is to generate Java source files which end up in target/generated-sources/**. This folder then becomes part of the source folder of the project, and compiled as usual into target/classes and packaged as usual. But these classes should not be part of the coverage report.

          In my case, I have a Maven module which only purpose is to generate such classes and package them into a jar. The module does not even have a src-folder because everything is generated from WSDLs/XSDs. The jacoco-maven-plugin correctly does not produce any jacoco.exec file for this module, but it seems like the Jenkins plugin sees the output classes, and no jacoco.exec, and interprets that as zero coverage.

          Rune Flobakk added a comment - I am guessing this is related to classes which are generated, e.g. from WSDLs. A common use case is to generate Java source files which end up in target/generated-sources/**. This folder then becomes part of the source folder of the project, and compiled as usual into target/classes and packaged as usual. But these classes should not be part of the coverage report. In my case, I have a Maven module which only purpose is to generate such classes and package them into a jar. The module does not even have a src-folder because everything is generated from WSDLs/XSDs. The jacoco-maven-plugin correctly does not produce any jacoco.exec file for this module, but it seems like the Jenkins plugin sees the output classes, and no jacoco.exec, and interprets that as zero coverage.

          David Barri added a comment -

          I'm having this issue too. The relevant part of my POM looks like this:

          <plugin>
          	<groupId>org.jacoco</groupId>
          	<artifactId>jacoco-maven-plugin</artifactId>
          	<version>0.6.0.201210061924</version>
          	<executions>
          		<execution>
          			<id>coverage-agent</id>
          			<phase>process-test-classes</phase>
          			<goals>
          				<goal>prepare-agent</goal>
          			</goals>
          		</execution>
          		<execution>
          			<id>coverage-report</id>
          			<phase>test</phase>
          			<goals>
          				<goal>report</goal>
          			</goals>
          		</execution>
          	</executions>
          	<configuration>
          		<excludes>
          			<!-- Exclude classes generated by AndroidAnnotations -->
          			<exclude>**/*_.*</exclude>
          			<exclude>**/*_$*</exclude>
          		</excludes>
          	</configuration>
          </plugin>
          

          When I generate a Jacoco HTML report, classes that end in an underscore like ExampleActivity_ do not appear because of the exclude settings in my POM. However from Jenkins all of those classes that the Maven build excludes are visible again.

          My Jenkins settings for this plugin are the defaults.

          Thanks!
          David

          David Barri added a comment - I'm having this issue too. The relevant part of my POM looks like this: <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.6.0.201210061924</version> <executions> <execution> <id>coverage-agent</id> <phase>process-test-classes</phase> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>coverage-report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> <configuration> <excludes> <!-- Exclude classes generated by AndroidAnnotations --> <exclude>**/*_.*</exclude> <exclude>**/*_$*</exclude> </excludes> </configuration> </plugin> When I generate a Jacoco HTML report, classes that end in an underscore like ExampleActivity_ do not appear because of the exclude settings in my POM. However from Jenkins all of those classes that the Maven build excludes are visible again. My Jenkins settings for this plugin are the defaults. Thanks! David
          Ognjen Bubalo made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]

          Ognjen Bubalo added a comment -

          Is this issue still actual?

          If yes, please show your configuration (given paths) of JaCoCo.

          Thanks,
          ogi

          Ognjen Bubalo added a comment - Is this issue still actual? If yes, please show your configuration (given paths) of JaCoCo. Thanks, ogi

          Thomas Zlika added a comment -

          Yes, the problem is still present with the latest 1.0.9 version.
          I have some packages excluded from code coverage using the "excludes" parameter of the jacoco-maven-plugin. The HTML page generated by this plugin are correct (the excludes packages are not taken into account). However, the Jenkins plugin take them into account and display a code coverage of 0%.
          The configuration for the Jenkins plugin is the standard one:

          • Path to exec files: **/target/jacoco.exec
          • Path to class dir: **/target/classes
            Path to source dir: **/src/main/java

          Thomas Zlika added a comment - Yes, the problem is still present with the latest 1.0.9 version. I have some packages excluded from code coverage using the "excludes" parameter of the jacoco-maven-plugin. The HTML page generated by this plugin are correct (the excludes packages are not taken into account). However, the Jenkins plugin take them into account and display a code coverage of 0%. The configuration for the Jenkins plugin is the standard one: Path to exec files: **/target/jacoco.exec Path to class dir: **/target/classes Path to source dir: **/src/main/java

          Mirko Friedenhagen added a comment - - edited

          Same here, I exclude the generated HelpMojo:

          Maven only needs the exclusion for the report mojo, though. jacoco's version is: 0.6.1.201212231917.
          Maybe the Jenkins-Plugin should just drop all .class files where no .java files are found?

          Mirko Friedenhagen added a comment - - edited Same here, I exclude the generated HelpMojo : in build https://github.com/1and1/bill-of-materials-maven-plugin/blob/a7c20afe67620df3c3be0458ddd23a596398af33/pom.xml#L134 and reporting https://github.com/1and1/bill-of-materials-maven-plugin/blob/a7c20afe67620df3c3be0458ddd23a596398af33/pom.xml#L166 Maven only needs the exclusion for the report mojo, though. jacoco 's version is: 0.6.1.201212231917. Maybe the Jenkins-Plugin should just drop all .class files where no .java files are found?

          Ognjen Bubalo added a comment -

          Hi,

          Hopefully I'll implement this feature and release a new version in the next 2 days.

          Cheers,
          Ogi

          Ognjen Bubalo added a comment - Hi, Hopefully I'll implement this feature and release a new version in the next 2 days. Cheers, Ogi

          Ognjen Bubalo added a comment -

          It will be available in the next release.

          Ognjen Bubalo added a comment - It will be available in the next release.
          Ognjen Bubalo made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: In Progress [ 3 ] New: Resolved [ 5 ]

            ognjenb Ognjen Bubalo
            daknin Darrell King
            Votes:
            23 Vote for this issue
            Watchers:
            29 Start watching this issue

              Created:
              Updated: