Reputation: 2365
I added the buildSrc folder to my android project to use kotlin-dsl in my gradle scripts. Now I want to add a kotlin file to buildSrc main containing functions, that I´ll use in gradle .kts scripts (buildSrc -> src -> main -> kotlin -> TheFile.kt). In one of them I´d like to use com.android.build.gradle.BaseExtension
. I see that this would be available in com.android.tools.build:gradle:x
. How can I include such dependencies to the buildSrc folder? My build.gradle.kts currently looks like this:
import org.gradle.kotlin.dsl.`kotlin-dsl`
plugins {
`kotlin-dsl`
}
repositories {
google()
jcenter()
}
Upvotes: 2
Views: 2035
Reputation: 21
You need to add the 'dependencies' block and include the com.android.tools.build:gradle:<VERSION>
dependency there:
plugins {
`kotlin-dsl`
}
repositories {
google()
jcenter()
}
dependencies {
implementation("com.android.tools.build:gradle:<VERSION>")
}
Upvotes: 2
Reputation: 1518
Put any .kt file to BuildSrc/src/main/kotlin directory.
Let say TheFile.kt with
object Config {
val myStringValue : String = "my string value"
val myIntValue : Int = 666
fun myFunction() : Int {
return 555
}
}
and now you can use this values in any build.gradle.kts like
something = Config.myStringValue
somethingelse = Config.myIntVale
someresult = Config.MyFunction()
Check Android Studio 3.2+ Kotlin DSL Gradle config boilerplate
Upvotes: -1