Skip Jacoco execution conditonally

1,054 views
Skip to first unread message

edward...@gmail.com

unread,
Apr 17, 2019, 1:21:07 PM4/17/19
to JaCoCo and EclEmma Users
Hi,

I'm trying to figure out how I can conditionally skip the Jacoco instrumentation and coverage analysis in a Gradle build. I don't want the coverage tasks to run in every execution of the build, I'd like to be able to control that using a command line property. I tried extracting the Jacoco code to its own Gradle file and using apply from: as in https://stackoverflow.com/questions/42501869/gradle-skip-jacoco-during-test, but this results in:

java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_1f1cc91.PreMain

Any insight on how to accomplish this?

Thanks,
Edward

Evgeny Mandrikov

unread,
Apr 17, 2019, 4:39:55 PM4/17/19
to JaCoCo and EclEmma Users
Hi,

JaCoCo plugin for Gradle is not developed by JaCoCo Team - see https://www.jacoco.org/jacoco/trunk/doc/integrations.html
and there is not much Gradle experts in this mailing list who provide answers,
so I would advice to use another channel for such Gradle-specific questions.


for following "build.gradle"

apply plugin: 'java'
apply plugin: 'jacoco'

repositories {
  mavenCentral()
}

dependencies {
  testCompile 'junit:junit:4.12'
}

test {
    jacoco {
        enabled = "$jacocoEnabled".toBoolean()
    }
}

and "src/main/java/Example.java"

class Example {
  void example() {
  }
}

and "src/test/java/ExampleTest.java"

public class ExampleTest {
  @org.junit.Test
  public void test() {
    new Example().example();
  }
}

execution of

gradle --info clean build -PjacocoEnabled=true

shows that JaCoCo Java Agent is used during execution of tests ( "java ... -javaagent:.../jacocoagent.jar ..." )
and file "build/jacoco/test.exec" is produced,
while execution of

gradle --info clean build -PjacocoEnabled=false

shows that agent is not used and file is not produced.

And the same in case of following "build.gradle"

apply plugin: 'java'

repositories {
  mavenCentral()
}

dependencies {
  testCompile 'junit:junit:4.12'
}

if ("$jacocoEnabled".toBoolean()) {
  apply plugin: 'jacoco'
}


Hope this helps.

edward...@gmail.com

unread,
Apr 17, 2019, 10:19:24 PM4/17/19
to JaCoCo and EclEmma Users
Thank you!
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages