3

I wanted to add JaCoCo to an existing Android Studio Project. In my settings.gradle I edited:

pluginManagement {

    gradle.ext.kotlin_version = "1.6.0"

    repositories {
        google()
        mavenCentral()
    }

    def versionsProp = new Properties()
    versionsProp["myapp.version.level"] = "7.1.0-beta05"

    def versionsPropFile = file("local.properties")
    if (versionsPropFile.canRead()) {

        versionsProp.load(new FileInputStream(versionsPropFile))
    }

    def levelVersion = versionsProp["myapp.version.level"]

    plugins {
        id("com.android.application") version "$levelVersion"
        id("com.android.library") version "$levelVersion"
        id("org.jetbrains.dokka") version "1.4.30"
        id("org.jetbrains.kotlin.android") version "$gradle.ext.kotlin_version"
        id("org.jacoco.core") version "0.8.7"
    } }

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        mavenLocal()
    } }

rootProject.name = "TestApp"

include ":app" 
include ":mylib_1" 
include ":mylib_2" 
include ":docs"

Especially I added JaCoCo in plugins section. According to this medium article :

Now inside each module’s build.gradle file apply the newly created jacoco.gradle as such: apply from: "$project.rootDir/jacoco.gradle"

But in my app modules build gradle (I've shortened away stuff commented there) I have follwing structure:

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
}

android {

    compileSdkVersion = 31
    buildToolsVersion = "31.0.0"

    defaultConfig {
        applicationId = "org.example.myapp"
        // minSdkVersion(21), targetSdkVersion(31) ..
    }

    // buildTypes, flavorOptions, compose options
    // compile options, kotlinOptions, buildFeatures, packagingOptions, lintOptions
}

dependencies {

    implementation(fileTree(include: ["*.jar"], dir: "libs"))

    implementation("androidx.activity:activity-compose:$compose_activity_version")
    implementation("androidx.appcompat:appcompat:$appcompat_version")

    testImplementation("junit:junit:4.13.2")

    implementation(project(":org_mylib_1"))
    implementation(project(":org_mylib_2"))
}

So where or how am I supposed to add the apply from: "$project.rootDir/jacoco.gradle"?

Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103

0 Answers0