This message was deleted.
# community-support
s
This message was deleted.
v
Where do you "not see" it? Can you provide an MCVE that shows your issue?
s
I'm just looking under the verification section in the Tasks lists in the gradle view in AS. I don't have a MCVE atm, but I can try to get one set up
v
Did you try to reload the project after doing the change? Do you see it in the output of
tasks
task?
s
if i try to run the jacocoTestReport task, it will fail since it can't find it
yeah i'm syncing and rebuilding
v
Ok, then an MCVE would definitely help. Either you to see your problem while creating or others to spot your problem
s
ok, i think this is somewhat close to what I'm working with: https://github.com/fluxxion82/TestReport I'm not seeing the reportTestReport task when i apply the plugin in the subprojects block, which isn't what I see in my other project. I have some plugin/task configs in my other project but just trying to figure out where the task is. I also expect to see a jacoco folder show up in the build folder with the exec file, but not seeing that either
v
Hm, maybe the Android plugin doing strange things and not being compatible with the built-in JaCoCo plugin?
s
any ideas on how to check? maybe it's gradle plugin? on my main project, i saw the jacoco folder and the tasks show up at some point, but not sure what conditions...i was changing the scripts around a bit before i noticed
v
I'm not doing Android. Maybe you had non-android projects and had seen the task there or something?
Other than that, set a breakpoint in the JaCoCo plugin class and debug the build
d
This one is fun with AGP. I’ve always had to register the task. As of AGP 7.3, you’ll want to use the onVariants API to say that unit test is finalized by generating jacoco test report + generating jacoco test report depends on unit test. e.g
Copy code
androidComponents {
  onVariants(selector().all(), { variant ->
    afterEvaluate {
      tasks.named("test${variant.getName().capitalize()}UnitTest").configure( {
        it.finalizedBy(project.tasks.named("generate${variant.getName().capitalize()}JacocoTestReports"))
      })
      tasks.named("generate${variant.getName().capitalize()}JacocoTestReports").configure( {
        it.mustRunAfter(project.tasks.named("test${variant.getName().capitalize()}UnitTest"))
        it.dependsOn(project.tasks.named("test${variant.getName().capitalize()}UnitTest"))
      })
    }
  })
}
You’ll want to configure the actual task for generating test coverage reports, this will just ensure that it gets added and executed properly.
s
so i've registered a task, which I see shows up under the Other section in the gradle task list in AS, but I don't see the jacocoTestReport task, which i guess is ok since my task is a jacoco report task. however, i don't see reports in my modules, except for two of them, which I think is because they don't use any android plugins really. I've been trying to do most of my configurations at the root level, although I've also been trying at the app level as well and combination of root level and app level. i see my other modules getting configured when i build gradle and run the tasks, but don't see any reports, except in two non android modules
d
How are you registering it? With build types and flavors, you'll want to define them
s
i've tried doing it per variant. something like
Copy code
tasks.register<JacocoReport>("${variant.name}CodeCoverageReport") {
                val kotlinDirectories = fileTree(
                    "${project.buildDir}/tmp/kotlin-classes/${variant.name}"
                ) { exclude(excludedFiles) }

                val coverageSrcDirectories = listOf(
                    "src/main/java",
                    "src/debug/java",
                    "src/us/java"
                )

                classDirectories.setFrom(files(kotlinDirectories))
                additionalClassDirs.setFrom(files(coverageSrcDirectories))
                sourceDirectories.setFrom(files(coverageSrcDirectories))
                executionData.setFrom(
                    files("${project.buildDir}/jacoco/test$${variant.name}UnitTest.exec")
                )
            }
that block in in the
Copy code
androidComponents {
    onVariants { variant ->
    }
}
block
d
needs to be attached to the project.
i.e., project.tasks
also, can’t remember if it changes with gradle or AGP, but it’s output is to
build/outputs/unit_test_code_coverage/
- https://issuetracker.google.com/issues/195860510 missed this on my end, https://developer.android.com/reference/tools/gradle-api/7.3/com/android/build/api/dsl/BuildType#enableUnitTestCoverage(). Perhaps just means you need to configure the tasks for the project and enable on the build type. Honestly, hadn’t noticed that addition until now.
s
so I see the jacoco folder showing up in a bunch of my modules again, but the folder is empty. I updated to agp 7.3, set
enableUnitTestCoverage
to true, registering a task with each variant, but no reports or exec files. don't see any outputs at the root of the project either, despite people saying that in the issue you linked. maybe there's something with my task configs 🤔
a
Were you able to resolve the JaCoCo related issues?
s
actually no..ran out of time to get things sorted but going to be picking things up again soon.
👍 1