Adrian Landborn
04/24/2023, 10:41 AMhelper.gradle.kts file with a fun that can be used in other x.gradle.kts files.
What is the best way?Adam S
04/24/2023, 10:45 AMAdrian Landborn
04/24/2023, 11:45 AMimport or apply as with Groovy scripts?Adam S
04/24/2023, 11:46 AMAdam S
04/24/2023, 11:49 AM./buildSrc/build.gradle.kts with
plugins {
`kotlin-dsl`
}
2. create ./buildSrc/settings.gradle.kts with
rootProject.name = "buildSrc"
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
@Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
3. create your file
// ./buildSrc/src/main/kotlin/myExtensions.kt
import org.gradle.api.*
fun Project.myHelper() {
println("I'm helping project ${project.displayName}!")
}
And then because there’s no package declaration in myExtensions.kt, you can use myHelper() in any subproject. If there was a package my.buildsrc.helpers, then you’d have to add import my.buildsrc.helpers.myHelper to any build.gradle.ktsAdrian Landborn
04/24/2023, 1:19 PM