https://kotlinlang.org logo
Title
i

igor.wojda

10/05/2018, 4:19 PM
Hi small problem here. I have this standard Android gradle configuration:
//build.gradle

import org.gradle.internal.impldep.com.amazonaws.PredefinedClientConfigurations.defaultConfig
import org.gradle.internal.impldep.org.junit.experimental.categories.Categories.CategoryFilter.include
import org.jlleitschuh.gradle.ktlint.KtlintExtension

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

android {
    compileSdkVersion(28)

    defaultConfig {
        minSdkVersion(28)
        targetSdkVersion(28)
        buildToolsVersion("28.0.2")

        versionCode = 1
        versionName = "1.0"
        testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
            proguardFiles("proguard-android.txt", "<http://proguard-rules.pro|proguard-rules.pro>")

        }
    }
}

dependencies {
    implementation(LibraryDependency.kotlin)

    //...
}
I want to extract above configuration into separate grade file, so I can easily reuse it in feature modules. I moved the code int one file and added it to build gradle files in feature modules:
//build.gradle.kts mosule1

apply(from = "${rootProject.file("common_feature.gradle.kts")}")
//build.gradle.kts mosule2

apply(from = "${rootProject.file("common_feature.gradle.kts")}")
//common_feature.gradle.kts
//Basicly all the above configuration that was initially in above build.gradle file and few delegates for configurations

import org.gradle.internal.impldep.com.amazonaws.PredefinedClientConfigurations.defaultConfig
import org.gradle.internal.impldep.org.junit.experimental.categories.Categories.CategoryFilter.include

val implementation by configurations
val testImplementation by configurations
val androidTestImplementation by configurations

plugins {
    id(GradlePluginId.androidFeature)
    id(GradlePluginId.kotlinAndroid)
}

android {
    compileSdkVersion(28)

    defaultConfig {
        minSdkVersion(28)
        targetSdkVersion(28)
        buildToolsVersion("28.0.2")

        versionCode = 1
        versionName = "1.0"
        testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
            proguardFiles("proguard-android.txt", "<http://proguard-rules.pro|proguard-rules.pro>")

        }

        getByName("debug") {
            isMinifyEnabled = false
        }
    }
}

dependencies {
    implementation(LibraryDependency.kotlin)
}
The problem with extracting the code into separate gradle file is that KTS compiler throws
Unresolved reference: android
error. Does someone know how to fix it?
g

gildor

10/08/2018, 2:36 AM
You cannot use type-safe accessors in script plugin. use
configure
instead
e

eskatos

10/08/2018, 7:43 AM