android studio go to declaration 不适用于 buildSrc

android studio go to declaration not working for buildSrc

我正在关注此 tutorial 以执行 Gradle 依赖管理:在 Android Studio

中将 Kotlin 和 buildSrc 用于 build.gradle 自动完成

在 Dependencies.kt 文件中

    object Versions {
        const val support_lib = "22.0.0"
        const val kotlin_version = "1.3.30"
        const val lifecycle_version = "1.1.1"
        const val rxjava_version = "2.2.8"
        const val rxandroid_version = "2.1.1"
    }

    object Modules{
        const val app = ":app"
        const val core = ":core"
    }

    object Libs {
        val support_appcompat_v7 = "com.android.support:appcompat-v7:${Versions.support_lib}"
        val constraint_layout = "com.android.support.constraint:constraint-layout:1.1.3"
        val lifecycle_extensions = "android.arch.lifecycle:extensions:${Versions.lifecycle_version}"
        val kotlin = "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin_version}"
        val rxjava2_rxjava = "io.reactivex.rxjava2:rxjava:${Versions.rxjava_version}"
        val rxjava2_rxandroid = "io.reactivex.rxjava2:rxandroid:${Versions.rxandroid_version}"

}

在应用中 build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example."
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }    
    kapt {
        generateStubs = true
    }
}

dependencies {

    implementation project(Modules.core)

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

    implementation Libs.support_appcompat_v7
    implementation Libs.constraint_layout
    implementation Libs.lifecycle_extensions

    implementation Libs.kotlin
    implementation Libs.rxjava2_rxjava
    implementation Libs.rxjava2_rxandroid
    }

repositories {
    mavenCentral()
}

项目编译构建成功,但是当我也尝试从应用build.gradle减速时dependencies.kt,它显示

首先,您需要将 groovy gradle 迁移到 kotlin dsl。只有这样你才能像 Dependencies.kt.

一样访问 Kotlin class

其次,您必须在 build.gradle.kts 中导入 Dependencies.kt 文件,就像在 java 中导入 classes 一样。

在 build.gradle

的开头添加以下行
import <package_name>.Dependencies.*