Saturday, October 14, 2023
HomeMobileKotlin 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 plenty 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), though a Kotlin (construct.gradle.kts) possibility has existed in Gradle for plenty 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 one default language used for all undertaking 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’ll 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 if you’re creating new initiatives or modules ranging from Android Studio Giraffe, you now get the Kotlin DSL by default. The up to date undertaking templates are a straightforward approach to get began with the brand new Kotlin DSL construct scripts. Emigrate current builds, take a look at the Kotlin DSL migration information.

Whereas the Kotlin DSL is the default for brand spanking new initiatives, giant, current Groovy DSL primarily based initiatives ought to wait on migrating whereas Gradle, JetBrains, and Google work on bettering construct efficiency additional. This work is ongoing and we’ll share updates as we make progress. Particularly, script compilation efficiency is slower than with the Groovy DSL. Nonetheless, not like 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 undertaking is not the one profit to this alteration, so let us 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 modifying Kotlin DSL construct scripts:
  • Syntax errors are extra correct, they usually’re displayed whereas modifying Kotlin DSL construct scripts, as an alternative of when making an attempt to sync the undertaking:
  • Get sort and methodology documentation by urgent Management+Q (Command+B on macOS).If you happen to want extra particulars you possibly can go to the underlying supply code by urgent Management+Click on (Command+Click on):
  • You’ll be able to combine Groovy DSL construct scripts and Kotlin DSL construct scripts in a single undertaking and migrate incrementally module by module. This permits new modules to make use of the Kotlin DSL whereas holding current modules on Groovy.

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

Model Catalogs provide you with a centralized, scalable manner of defining your undertaking’s dependencies. Whereas utilizing Model Catalogs is elective, they pair nice with the Kotlin DSL by offering extra sort security in your construct definitions.

To find out about migrating to Model Catalogs, take a look at the migration information.

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





Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments