Gradle Kotlin DSL 1.0

Paul Merlin
This is a guest blog post from Paul Merlin
software engineer for Gradle

The recently released Gradle 5.0 includes the Gradle Kotlin DSL v1.0 which is now ready for widespread use.

We want you to enjoy a build authoring experience with the benefits provided by Kotlin’s static type system in Intellij IDEA and Android Studio: auto-completion, smart content assist, quick access to documentation, navigation to source and context-aware refactoring.

To view the video in Safari you may need to install the VLC Web Browser Plugin.

In case you missed it, you can watch Paul Merlin demonstrate these benefits in the Type-safe build logic with Gradle Kotlin DSL video from KotlinConf 2018.

If you prefer the flexibility and dynamic features of Groovy, that’s totally okay — the Groovy DSL will not be deprecated.

Using the Kotlin DSL today

You can get started quickly by following the Creating New Gradle Builds guide. You can also follow one of the other guides like Building Kotlin JVM Libraries or Building Java Applications.

The Gradle Kotlin DSL Primer user manual chapter is the best place to start learning more: it will cover all the basics and answer most of your questions.

If you are working with an existing build using the Gradle Groovy DSL you’ll be interested in the Migrating build logic from Groovy to Kotlin guide.

Several community plugins now have Gradle Kotlin DSL snippets in their documentation: Spring Boot, Docker, Detekt, Kotlinter, APT, Android JUnit 5, Android Check 2, Android Play Publisher and the list goes on.

Last but not least, the Gradle documentation contains build script excerpts that demonstrate both the Groovy DSL and the Kotlin DSL. This is the best place to find how to all things with each DSL; and it covers all Gradle features.

Again, a big thank you to all who helped make this a reality!

Feedback wanted

Community involvement has been instrumental to reach 1.0. It is also crucial going forward.

We want to know what you think works well or poorly in the Kotlin DSL. Feedback on the IDE experience, logging, and everything in between is welcome. Please discuss through the Kotlin DSL issue tracker or the #kotlin-dsl channel on Gradle Community Slack (which you can join using this link).

This entry was posted in community, guestpost, Tools and tagged . Bookmark the permalink.

10 Responses to Gradle Kotlin DSL 1.0

  1. HGH says:

    I don’t know Groovy at all. I have setup a build in such way that I want it. It is a Android project and changes the defaulqt template quite a bit (because I think that mixing build artifacts and other autogenerated garbage is stupid and that’s what Google does by default). I tried to convert the Groovy to Kotlin DSL but is not at all clear how to express the same statements. Maybe an auto-coverter or IDE tips would be of a great help.
    Or maybe more elaborate examples of Groovy to Kotlin coversion would be helpful.

  2. hhh says:

    It‘s a nice job. I can’t wait to try it.

    Are there some examples for one projects, mulit-projects?

    By the way:

    how about to convert:

    apply from: _repo

  3. ian says:

    The big barrier is that koltin multi-platform is currently only supported with groovy, and supported by the kotlin dsl. Since so many of our projects already moving to multi-platform, the kotlin gradle dsl is some what of a dead end at this time.

    • alexeybelkov says:

      Kotlin Gradle DSL support for MPP is coming in 1.3.20: https://youtrack.jetbrains.com/issue/KT-26389

      • ian says:

        Now that is a fast response! (Given that EAP of 1.3.20 was just released). If there is just one example it would really help.

        Intellij will build an iOS/Android app sample and the project level gradle files can be converted, but the app level falls over at the fromPreset and a couple of other places… or being able to convert the sample multi-platform lib would be helpful. The notes seem to suggest later these will be able to be created as kotlin DSL automatically, but in the interim a sample being somewhere would help.

        Clearly things are almost there! With even just samples, they are there.

  4. kango says:

    If you have an open source project and want to let developers choose their IDE, you may as well use Groovy in Gradle. as The Kotlin DSL is pretty much IDEA only. This is the biggest barrier to moving to Kotlin is that it is controlled by a single company.

  5. Sola says:

    Sorry for spam but I really want to see some update on this: https://youtrack.jetbrains.com/issue/KT-25010

  6. Pingback: Gradle Kotlin DSL 1.0 - Kotlin Blog

Comments are closed.