Jacoco integration for excluding files in the codecoveragereport

I try to exclude a couple of files when creating a code coverage report when executing the task createDebugCoverageReport

I have used ChatGPT and it says that I should use the following:

android {
    // ...

    buildTypes {
        debug {
            testCoverageEnabled true

    jacoco {
        excludes = ['**/MainActivity.*']

I’m using and android application in Android Studio, an when I sync with the gradle changes, I get the error:

Could not set unknown property ‘excludes’ for object of type com.android.build.gradle.internal.coverage.JacocoOptions.

Any ideas why it isn’t working? I can provide all my gradle file if necessary.

Any ideas why it isn’t working?

Because you trust a liar.

ChatGPT is good to get answer that look correct, but seldomly to get answers that are correct from what I have seen so far.
Besides that its knowledge is older than 2 years.
ChatGPT is a fancy toy, but you can imho use it only for things you could have done entirely yourself but are too lazy to (the good lazy, not the bad one).
Because you always need to verify what it answers and fix the non-sense it does.
It also uses for example methods on APIs that never existed and things like that.

ChatGPT answers are also banned from StackOverflow for good reasons: Temporary policy: ChatGPT is banned - Meta Stack Overflow

For example, testCoverageEnabled is deprecated and replaced by enableUnitTestCoverage and enableAndroidTestCoverage.

And jacoco { ... } is deprecated and replaced by testCoverage { ... }, besides that both blocks only allow to configure the JaCoCo version to use and not any exccludes. That part was just again totally made up by ChatGPT.

I strongly recommend to use Kotlin DSL instead of Groovy DSL for your build scripts, then you immediately get type-safe build scripts, much more helpful error messages in many situations and most importantly amazingly better IDE support when using a proper IDE like IntelliJ or Android Studio.

As I’m not an Android developer I cannot tell you how to properly configure it though, I’m sorry.