Apps

Kotlin DSL is Now the Default for New Gradle Builds

[ad_1]


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 increased productiveness and extra steady apps. Nevertheless the default language to outline builds has been Groovy (construct.gradle), regardless that a Kotlin (construct.gradle.kts) possibility has existed in Gradle for quite a lot of years.

Immediately we’re excited to announce that we’re switching the default language for construct scripts to Kotlin! Which means Kotlin is the one default language used for all challenge 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 Blog; JetBrains Blog.

This doesn’t have an effect on present 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 challenge templates are a straightforward technique to get began with the brand new Kotlin DSL construct scripts. Emigrate present builds, take a look at the Kotlin DSL migration guide.

Whereas the Kotlin DSL is the default for brand new initiatives, massive, present 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. Nevertheless, 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 challenge is not the one profit to this modification, 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, and so they’re displayed whereas modifying Kotlin DSL construct scripts, as an alternative of when making an attempt to sync the challenge:
  • 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 may combine Groovy DSL construct scripts and Kotlin DSL construct scripts in a single challenge and migrate incrementally module by module. This allows new modules to make use of the Kotlin DSL whereas retaining present modules on Groovy.

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

Model Catalogs offer you a centralized, scalable manner of defining your challenge’s dependencies. Whereas utilizing Model Catalogs is non-compulsory, 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 guide.

The brand new Kotlin DSL default change is offered now in Android Studio Giraffe previews. Please attempt it and let us know how it goes!



[ad_2]

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button