1

我想将 JaCoCo 添加到现有的 Android Studio 项目中。在我的 settings.gradle 中,我编辑了:

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"

特别是我在插件部分添加了 JaCoCo。根据这篇媒体文章

现在在每个模块的 build.gradle 文件中应用新创建的 jacoco.gradle:apply from: "$project.rootDir/jacoco.gradle"

但是在我的应用程序模块中构建 gradle (我已经缩短了那里评论的内容)我有以下结构:

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"))
}

那么我应该在哪里或如何添加apply from: "$project.rootDir/jacoco.gradle"

4

0 回答 0