Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Applieng *kts from groovy does not work correctly #843

Closed
StefMa opened this issue Apr 27, 2018 · 2 comments
Closed

Applieng *kts from groovy does not work correctly #843

StefMa opened this issue Apr 27, 2018 · 2 comments

Comments

@StefMa
Copy link
Contributor

StefMa commented Apr 27, 2018

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 :/

Expected Behavior

I want that the dependencies.gradle.kts works like the dependencies.gradle before.

Current Behavior

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

Context

Don't know if the "interop" between *kts and groovy is broken or something different ...
Maybe related to #803 ?

Steps to Reproduce (for bugs)

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

Your Environment

Gradle: 4.7

@eskatos
Copy link
Member

eskatos commented Apr 27, 2018

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

@StefMa
Copy link
Contributor Author

StefMa commented May 3, 2018

Thank you for the answer @eskatos

@StefMa StefMa closed this as completed May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants