Kotlin-dsl-samples: root build.gradle.kts didn't work with buildSrc used in dependencies

Created on 9 Dec 2018  路  7Comments  路  Source: gradle/kotlin-dsl-samples

When use root build.gradle.kts file and inside buildscript > dependencies variables from buildSrc build failed. When use without buildSrc or when not use kts file but juts Groovy build.gradle variables works.

Expected Behavior

Build project without failure

Current Behavior

Fail on

Script compilation errors:

  Line 18:         classpath(Config.BuildPlugins.androidPlugin)
                             ^ Unresolved reference: Config

Steps to Reproduce (for bugs)

Demo project with reproducible bug: https://github.com/mtrakal/kotlinDslbug

Diff file from working to not workign project (rename file and change lines): https://github.com/mtrakal/kotlinDslbug/commit/09a5db46a10ed0c6d30942e3eede8b1787d7721a

Your Environment

See on demo project

Maybe related with second issue with default namespace: https://github.com/gradle/kotlin-dsl/issues/1088

duplicate

Most helpful comment

same as: https://github.com/gradle/kotlin-dsl/issues/939
https://github.com/gradle/kotlin-dsl/issues/1319

same for plugins block:

plugins {
    id("com.gradle.build-scan") version cz.bs.Config.Versions.buildScanVersion
}

vs

import cz.bs.Config;

plugins {
    id("com.gradle.build-scan") version Config.Versions.buildScanVersion
}

All 7 comments

Gradle 5.1.1 with Gradle DSL, still not working as expected.

CONFIGURE FAILED in 4s
Script compilation errors:

  Line 33:         classpath("com.android.tools.build:gradle:${Config.Versions.gradleBuildTools}")
                                                               ^ Unresolved reference: Config

  Line 34:         classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Config.Versions.kotlinVersion}")
                                                                          ^ Unresolved reference: Config

  Line 35:         classpath("com.google.android.gms:oss-licenses-plugin:${Config.Versions.PlayServices.ossLicensesPlugin}")
                                                                           ^ Unresolved reference: Config

  Line 36:         classpath("com.google.gms:google-services:${Config.Versions.googleServicesVersion}")
                                                               ^ Unresolved reference: Config
classpath("com.android.tools.build:gradle:${Config.Versions.gradleBuildTools}")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Config.Versions.kotlinVersion}")
        classpath("com.google.android.gms:oss-licenses-plugin:${Config.Versions.PlayServices.ossLicensesPlugin}")
        classpath("com.google.gms:google-services:${Config.Versions.googleServicesVersion}")

same as: https://github.com/gradle/kotlin-dsl/issues/939
https://github.com/gradle/kotlin-dsl/issues/1319

same for plugins block:

plugins {
    id("com.gradle.build-scan") version cz.bs.Config.Versions.buildScanVersion
}

vs

import cz.bs.Config;

plugins {
    id("com.gradle.build-scan") version Config.Versions.buildScanVersion
}

Any progress here? Is there a workaround something like that?

@luxmeter workaround is on my previous comment... 馃檭. Use fully qualified package name

Hi, thanks for the quick reply. you mean to full qualify the class? What exactly do you mean? To use groovy instead?
The comment with the workaround is not obvious to me :)

Fully qualified in this context means, that you can't import the package and use only the class name. So for the above example, it must be cz.bs.Config.BuildPlugins.androidPlugin instead of importing the cz.bs package and use only Config.BuildPlugins.androidPlugin for the variable name.

See also the documentation/tuorial of Java for package names: https://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html

Was this page helpful?
0 / 5 - 0 ratings