I have an android project where I have a separate dependencies.gradle file.
I've just shifted that to dependencies.gradle.kts. Now Gradle don't recognize any implementation configuration anymore :/
I want that the dependencies.gradle.kts works like the dependencies.gradle before.
If I try to run it prints:
Script compilation errors:
Line 2: implementation("com.android.support:appcompat-v7:27.1.1")
^ Unresolved reference: implementation
Line 3: implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.30")
^ Unresolved reference: implementation
Line 4: implementation("org.jetbrains.kotlin:kotlin-reflect:1.2.30")
^ Unresolved reference: implementation
Line 5: testImplementation("junit:junit:4.12")
^ Unresolved reference: testImplementation
Line 6: androidTestImplementation("com.android.support.test:runner:1.0.1")
^ Unresolved reference: androidTestImplementation
Line 7: androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.1")
^ Unresolved reference: androidTestImplementation
Don't know if the "interop" between *kts and groovy is broken or something different ...
Maybe related to #803 ?
This is my code:
build.gradle
apply plugin: 'com.android.application'
apply from: 'dependencies.gradle.kts'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies.gradle.kts
dependencies {
implementation("com.android.support:appcompat-v7:27.1.1")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.30")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.2.30")
testImplementation("junit:junit:4.12")
androidTestImplementation("com.android.support.test:runner:1.0.1")
androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.1")
}
Gradle: 4.7
Thanks for the very well done report @StefMa!
This is expected. The Gradle Kotlin DSL can't know at script compilation time that these configurations will be available when the script is applied, it could be applied by any other script. Hence the Kotlin extensions for these configuration not being available at script compilation time. You have to reference the configurations by name at runtime.
Either by string:
// dependencies.gradle.kts
dependencies {
"implementation"("com.android.support:appcompat-v7:27.1.1")
"implementation"("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.30")
"implementation"("org.jetbrains.kotlin:kotlin-reflect:1.2.30")
"testImplementation"("junit:junit:4.12")
"androidTestImplementation"("com.android.support.test:runner:1.0.1")
"androidTestImplementation"("com.android.support.test.espresso:espresso-core:3.0.1")
}
or by bringing them into scope:
// dependencies.gradle.kts
val implementation by configurations
val testImplementation by configurations
val androidTestImplementation by configurations
dependencies {
implementation("com.android.support:appcompat-v7:27.1.1")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.30")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.2.30")
testImplementation("junit:junit:4.12")
androidTestImplementation("com.android.support.test:runner:1.0.1")
androidTestImplementation("com.android.support.test.espresso:espresso-core:3.0.1")
}
Thank you for the answer @eskatos
Most helpful comment
Thanks for the very well done report @StefMa!
This is expected. The Gradle Kotlin DSL can't know at script compilation time that these configurations will be available when the script is applied, it could be applied by any other script. Hence the Kotlin extensions for these configuration not being available at script compilation time. You have to reference the configurations by name at runtime.
Either by string:
or by bringing them into scope: