https://kotlinlang.org logo
#getting-started
Title
# getting-started
u

Umar Ata

01/23/2022, 9:26 AM
Hi Why Android studio is still providing gradle files in groovy, even kotlin scripts are working perfectly fine? Any idea how can I create a new project in Android studio that generates kotlin scripts gradle files not groovy
t

tomas-mrkvička

01/23/2022, 9:54 AM
Groovy vs Kotlin - just take a look at https://github.com/gradle/gradle/issues/15886
u

Umar Ata

01/23/2022, 9:59 AM
So if I have only Android project not kotlin multi-platform so it is good to use groovy and not move to kotlin gradle scripts?
t

tomas-mrkvička

01/23/2022, 10:09 AM
If both DSLs offer the functionality you need then its up to you whether you want to sacrifice performance and overall build time over "new fancy dsl". Everybody has its own taste 🙂 Personally I stick with Groovy until the performance is similar at least.
u

Umar Ata

01/23/2022, 10:22 AM
Honestly speaking i also prefer groovy for gradle because of template generated by Android Studio in it, otherwise I need to do some extra work on it to make it kotlin. But since I was assigned a project that needs to be done 100% in kotlin so I thought if I refactor my gradle files too to kotlin Apart from this I created a very cool project in kotlin multi-platform with kotlin gradle scripts and I enjoyed a lot. I am working as Android developer since 2015 and in this phase I saw many changes in whole app architecture and tools.
t

tomas-mrkvička

01/23/2022, 10:40 AM
+1! Enjoy what you like. There is simply no good/wrong way (unless you hit Gradle bugs).
v

Vampire

01/23/2022, 12:23 PM
Just for those not reading that issue past the first post, last measurements with Gradle 7 were that for first use and abi change Groovy is ~1.5 times faster while for non-abi change Kotlin is ~5 times faster. I personally only use Kotlin DSL by now if I have a choice. It is not just "new fancy DSL". It is much much much more convenient to work with. Because of the type-safety many bugs simply cannot happen and the IDE support including highlighting, completion and so on is just amazing with Kotlin DSL compared to groovy DSL. I'll always trade the performance difference for that.
l

loke

01/23/2022, 12:34 PM
@Vampire I'd like to switch to Kotlin DSL for that reason. But given the fact that Gradle is complicated as it is, I have no idea how to migrate my scripts.
v

Vampire

01/23/2022, 12:41 PM
Imho it is not complicated, at least for the usual stuff, but that is purely subjective of course. Most things are pretty similar between Groovy and Kotlin DSL. Just some things needed to be different because of the dynamic nature of groovy. https://docs.gradle.org/current/userguide/kotlin_dsl.html should probably give you a good start.
l

loke

01/23/2022, 12:54 PM
My project is a multiplatform project with a lot of modules where the gradle files have been cargoculted together as I find Gradle to be barely understandable on a good day. 🙂
Not asking anyone to do any work for me, but I'm sharing a link here just in case you're curious: https://github.com/lokedhs/array
3 Views