HomeAndroidKotlin DSL is Now the Default for New Gradle Builds

Kotlin DSL is Now the Default for New Gradle Builds



Posted by James Ward, Product Supervisor, Kotlin and Boris Farber, Developer Relations Engineer

Android has been Kotlin-first for 4 years and lots of Android builders have made the swap leading to larger productiveness and extra secure apps. Nonetheless the default language to outline builds has been Groovy (construct.gradle), despite the fact that a Kotlin (construct.gradle.kts) possibility has existed in Gradle for quite a lot of years.

At present we’re excited to announce that we’re switching the default language for construct scripts to Kotlin! Because of this Kotlin is the only default language used for all venture code, together with UI with Jetpack Compose, and now construct scripts! We have been working with the Gradle and JetBrains groups on this enchancment, and you may learn extra of their associated bulletins: Gradle Weblog; JetBrains Weblog.

This doesn’t have an effect on current initiatives utilizing Groovy, as these will proceed working with no plans for deprecation. However in case you are creating new initiatives or modules ranging from Android Studio Giraffe, you now get the Kotlin DSL by default. The up to date venture templates are a straightforward method to get began with the brand new Kotlin DSL construct scripts. Emigrate current builds, try the Kotlin DSL migration information.

Whereas the Kotlin DSL is the default for brand new initiatives, massive, current Groovy DSL primarily based initiatives ought to wait on migrating whereas Gradle, JetBrains, and Google work on enhancing construct efficiency additional. This work is ongoing and we are going to share updates as we make progress. Particularly, script compilation efficiency is slower than with the Groovy DSL. Nonetheless, in contrast to with the Groovy DSL, the Kotlin DSL script compilation outcomes are saved in Gradle native and distant caches in order that subsequent builds don’t want recompilation.

Having a single language for all code in a venture is not the one profit to this alteration, so let’s take a look at another nice issues about utilizing the Kotlin DSL for Gradle builds.

  • Kotlin is statically typed so that you get fast and correct code hints whereas enhancing Kotlin DSL construct scripts:
  • Syntax errors are extra correct, they usually’re displayed whereas enhancing Kotlin DSL construct scripts, as an alternative of when making an attempt to sync the venture:
  • Get kind and methodology documentation by urgent Management+Q (Command+B on macOS).Should you want extra particulars you may go to the underlying supply code by urgent Management+Click on (Command+Click on):
  • You possibly can combine Groovy DSL construct scripts and Kotlin DSL construct scripts in a single venture and migrate incrementally module by module. This allows new modules to make use of the Kotlin DSL whereas preserving current modules on Groovy.

An related change we’re additionally making to the New Challenge templates is an experimental possibility to make use of Gradle Model Catalogs with Kotlin DSL construct scripts.

Model Catalogs offer you a centralized, scalable approach of defining your venture’s dependencies. Whereas utilizing Model Catalogs is optionally available, they pair nice with the Kotlin DSL by offering extra kind security in your construct definitions.

To find out about migrating to Model Catalogs, try the migration information.

The brand new Kotlin DSL default change is on the market now in Android Studio Giraffe previews. Please attempt it and tell us the way it goes!



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments