Removing Jacoco library dependency while exporting project as jar

36 views
Skip to first unread message

onurka...@gmail.com

unread,
Mar 27, 2019, 5:30:20 AM3/27/19
to JaCoCo and EclEmma Users
Hi,

I've created the topic in stackoverflow, but even after offering a bounty, not a satisfying reply came actually, so I'm here.

The topic is there: https://stackoverflow.com/questions/55301766/removing-jacoco-library-dependency-while-exporting-project-as-jar

Simply what I have and what I'm trying to do is:
- We have an SDK project written on Android, started to use Jacoco a few months ago, and after that time everytime we export the project as .jar, whether we set the "testCoverageEnabled" true or not, it's causing crash on the app that uses our .jar file as a library.

The crash is:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_8ff85ea/Offline;

Which is kinda popular crash when implementing to the project, but for an sdk project it is weird, as of course jacoco dependency shouldn't be in the library somehow.

So is there a possibility to exclude jacoco dependencies while exporting the application?

implementation is something like that: (I've tried with adding additional classpath for offline solution and also with the jacoco version of 0.8.3)

gradle:
classpath 'org.jacoco:org.jacoco.core:0.8.1'

jacoco {
toolVersion = '0.8.1'
}

//this adds robolectric tests to coverage report
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testProductionDebugUnitTest',
'createProductionDebugCoverageReport']) {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."

reports {
xml.enabled = true
html.enabled = true
html.setDestination(new File("$project.buildDir/reports/jacoco/html"))
}

def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*',
'android/**/*.*']
def debugTree = fileTree(dir: "$project.buildDir/intermediates/classes/production/debug", excludes: fileFilter)
def mainSrc = "$project.projectDir/src/main/java"

sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: project.buildDir, includes: ['**/*.exec', '**/*.ec'])
}

Thanks in advance!

Marc Hoffmann

unread,
Mar 27, 2019, 10:37:40 AM3/27/19
to jac...@googlegroups.com
Hi,

the error shows that the JAR file you’re exporting contain classes instrumented by JaCoCo. This should not be the case for exported JARs.

Please ask the Android or Gradle project how to configure you’re build correctly (both are not maintained by us).

Also try to follow the answers on SO. They look very reasonable to me.

Regards,
-marc
> --
> 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 jacoco+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/8c523800-c5d7-4943-b5cf-51108042e8d6%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Evgeny Mandrikov

unread,
Mar 27, 2019, 10:51:53 AM3/27/19
to JaCoCo and EclEmma Users

On Wednesday, March 27, 2019 at 3:37:40 PM UTC+1, Marc R. Hoffmann wrote:
Also try to follow the answers on SO. They look very reasonable to me.

BTW one of them ( https://stackoverflow.com/a/55347775/244993 ) already cites statement of one of JaCoCo developers:

Android Plugin for Gradle, when instructed to measure coverage using JaCoCo, uses offline instrumentation and therefore requires two types of build - with coverage and without for release.

;)


What however could be added based on statement

On Wednesday, March 27, 2019 at 10:30:20 AM UTC+1, onurka...@gmail.com wrote:

whether we set the "testCoverageEnabled" true or not


check more carefully that coverage/instrumentation is really disabled,
then check more carefully from where/how instrumented classes come to your jar - dependencies, transitive dependencies, caches, etc.

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages