JaCoCo coverage not working

I've enabled the jacoco coverage feature in my ant build on the TC server.  I don't see the Code Coverage tab after the build runs.  Any thoughts would be much appreciated.

I see the following in my build log:


Here is the resulting jacoco.log:

Jacoco report builder run with arguments: [-dataPaths, '/home/ci/buildAgent/temp/buildTmp/JACOCO8526525118464185903coverage/jacoco.exec', -sr, '.', -cp, '+:build/**/*.class +:dist/**/*.class', -i, '*', -rd, '/home/ci/buildAgent/temp/buildTmp/JACOCO8526525118464185903coverage/report', -t, 'Build Pipeline', -l, 'true']
Exec files loaded in: 384
Filter set up with includes: *; excludes: <none>
Classfiles read in: 122
Info headers read in: 0
Creating SourceCodeFinder from .
Source files read in: 485
Report written in: 1142
Jacoco report builder exits normally


Here is the resulting coverage.params file:

#
#Thu Jul 17 13:13:25 MDT 2014
teamcity.jacoco.coverage.datafile=/home/ci/buildAgent/temp/buildTmp/JACOCO8526525118464185903coverage/jacoco.exec
teamcity.coverage.jacoco.includePatterns=*
teamcity.coverage.jacoco.sources=.
teamcity.coverage.jacoco.classpath=+\:build/**/*.class +\:dist/**/*.class
0
8 comments

Hi,

Parameters look correctly. Please make sure that the paths to classes are valid and also that your tests run in the fork=true mode.

0
Avatar
Permanently deleted user

I've been able to make some headway on this issue.

I'm now getting the report to generate and show up on TeamCity.  However, the report seems to be missing some of my test classes.  I say this because I have unit tests that exercise various src classes that are not showing up as being covered on the report.  Here's what I've defined as my Classfile directories or jars value:

+:**/build/main/**/*.class
+:**/classes/**/*.class
-:**/build/test/**/*.class
-:**/test-classes/**/*.class

I've verified that the test classes I'm compiling are indeed within a test-classes directory.  Thoughts?

The weirdest part of this issue is that other test classes in the same directory and package are showing up on the report.  For example, given the following:

src

com.foo.Foo.java

com.foo.Bar.java

test

com.foo.TestFoo.java

com.foo.TestBar.java

I see the com.foo package and results for com.foo.Foo, but not com.foo.Bar.

0

Could you please attach jacoco.log, jacoco.exec (hidden artifacts) and build log files?

0
Avatar
Permanently deleted user

These tips are proving helpful.  I'm seeing a lot of the following:

java.io.IOException: Error while analyzing class /home/ci/depot/./other-agent-root/prj/product/foo/dist/classes/com/foobar/MyClass.class.
    at org.jacoco.core.analysis.Analyzer.analyzerError(Analyzer.java:150)
    ...
Caused by: java.lang.IllegalStateException: Can't add different class with same name: com/foobar/MyClass
    at org.jacoco.core.analysis.CoverageBuilder.visitCoverage(CoverageBuilder.java:106)
    ...
    ... 6 more

I believe this is due to a failure to exclude certain directories from the jacoco classpath.  Specifically, I'm attempting to exclude the other-agent-root directory with the following: -:**/other-agent-root/**/*.class

Here's a snippet of my jacoco.log:

Jacoco report builder run with arguments: [-dataPaths, '/home/ci/buildAgent/temp/buildTmp/JACOCO7616972526584307278coverage/jacoco.exec', -sr, '.', -cp, '+:**/build/main/**/*.class +:**/classes/**/*.class -:**/build/test/**/*.class -:**/test-classes/**/*.class -:**/other-agent-root/**/*.class', -i, '*', -e, 'com.red.* com.orange.* com.blue.*', -rd, '/home/ci/buildAgent/temp/buildTmp/JACOCO7616972526584307278coverage/report', -t, 'Build Pipeline', -l, 'true']
Exec files loaded in: 388
Filter set up with includes: *; excludes: com.red.* com.orange.* com.blue.*

0

It's a known issue - http://youtrack.jetbrains.com/issue/TW-36758, which have been already fixed. Please upgrade to TeamCity 8.1.4.

0
Avatar
Permanently deleted user

So is my exclusion pattern incorrect or not working due to this bug?

0

It is due to this bug. As workaround you can exclude classes with the same names.

0

Hi Alina Mishina - facing similar issue "[Ant output] Caused by: java.lang.IllegalStateException: Can't add different class with same name"

I'm using ant build in my codebase. As per one of your comments to upgrade TeamCity 8.1.4, but I'm using latest version TeamCity Enterprise 2021.2.3.

Pls suggest me what is required to fix this issue.

Thank you

0

Please sign in to leave a comment.