Search code examples
gradlegradle-kotlin-dsl

Can we import kotlin build files from buildSrc into settings.gradle?


Is something like this possible? Currently, this gives unable to resolve class error.

Settings.kt file in buildSrc

object Settings {
    const val useLocal = true
}

settings.gradle

import com.example.android

gradle.ext {
   useLocal = Settins.useLocal
}

include ':app'

Solution

  • It was possible in older versions of Gradle (before Gradle 6).

    https://docs.gradle.org/current/userguide/upgrading_version_5.html#changes_to_plugins_and_build_scripts

    Classes from buildSrc are no longer visible to settings scripts

    Previously, the buildSrc project was built before applying the project’s settings script and its classes were visible within the script. Now, buildSrc is built after the settings script and its classes are not visible to it. The buildSrc classes remain visible to project build scripts and script plugins.