Edit
After reading the second answer and testing it myself I greatly suggest and appreciate the below blog post as it's true the instrumentation still happens even after disabling or removing the tasks.
https://poetengineer.postach.io/post/how-to-conditionally-enable-disable-jacoco-in-gradle-build
If it does runs on Jenkins, error 137 might be out of memory issue.
If it runs on Jenkins please try to extend the memory and check this link.
I'm getting OutOfMemoryError
Jacoco tasks:
jacocoTestReport - JacocoReport Generates code coverage report for the test task.
jacocoTestCoverageVerification - JacocoCoverageVerification Verifies code coverage metrics based on specified rules for the test task.
To find out which tasks have which dependencies you can do
gradle tasks --all
To exclude the task with cmd you can
gradle test -x taskToExclude
Programmatically you can use a task graph to exclude it
gradle.taskGraph.useFilter { task -> yourstuff}
or simply remove it from test task dependencies
test.dependsOn.remove("jacocoTestReport")
test.dependsOn.remove("jacocoTestCoverageVerification")
Additional resource worth checking:
https://docs.gradle.org/current/userguide/jacoco_plugin.html