I'm a newbie in Kotlin and I'm currently learning how to integrate Gradle with Kotlin. Looking up in the internet I saw this code.
import org.gradle.api.Project
import org.gradle.kotlin.dsl.*
/**
* Configures the current project as a Kotlin project by adding the Kotlin `stdlib` as a dependency.
*/
fun Project.kotlinProject() {
dependencies {
"compile"(kotlin("stdlib"))
}
}
This is saved as buildSrc/src/main/kotlin/Dependencies.kt. Because Kotlin has so many syntactic sugars I have a bit of a trouble understanding that piece of code. The "compile"() part, that is an invoke() convention? Can anyone provide an explanation for this code and the Gradle buildSrc, as to why the code looks like that?
Here is the buildSrc/build.gradle.kts file
plugins {
`kotlin-dsl`
}
repositories {
jcenter()
}
Here is another build.gradle.kts in the root directory
plugins {
base
kotlin("jvm") version "1.3.72" apply false
}
allprojects {
group = "com.example.test"
version = "1.0"
repositories {
jcenter()
}
}
dependencies {
// Make the root project archives configuration depend on every sub-project
// subprojects.forEach {
// archives(it)
// }
}```