Set up Kotlin source directory from Gradle Kotlin DSL
Published on · Updated on
1 minute read
When converting Android Gradle files from Groovy to Kotlin, one thing that may not be clear is how to keep Kotlin sources within src/main/kotlin
. We simply need to get the source sets by name and call java.srcDirs()
as a function call. Works like a dream!
sourceSets {
getByName("main").java.srcDirs("src/main/kotlin")
getByName("test").java.srcDirs("src/test/kotlin")
getByName("androidTest").java.srcDirs("src/androidTest/kotlin")
}
I hope the article was useful. If you have any feedback or questions please feel free to reach out to me on Twitter.
Thanks for reading and happy coding!
Hi, I hope you enjoyed the article. I am Andrew - a builder of apps and developer tools. Articles on the blog focus on all aspects of Android and iOS development using Kotlin and Swift.
Subscribe via RSS
Want to read more?
Here are some other articles you may enjoy.