Migrating build logic from Groovy to Kotlin in few Steps

Sana Ebadi
3 min readApr 10, 2020

--

Migrating build logic from Groovy to Kotlin in few Steps
Migrating build logic from Groovy to Kotlin in few Steps

Gradle 5.0 has been released with lots of features and especially with the support of production-ready Kotlin DSL.

Note: To have Gradle files in Kotlin language, be sure to check the Gradel version of the project. You must have version 5 and above

STEP 1 :

Convert all single quotes to double-quotes. That is, change all the ‘ to “ ! use CTRL + SHIFT + R shortcuts.

STEP 2 :

Convert all spaces to () or =. If it is a function, then we must use (), but if we are dealing with property, then we use =.

Step 3:

In the build.gradle file of the module, change the plugins section as follows:

STEP 4:

Add .kts to the end of gradle files. This means that the settings.gradle file will be converted to settings.gradle.kts, and do the same for future files.

STEP 5:

In the build.gradle file, the project level of the task / clean section undergoes changes:

Also in the build.gradle file, the level of the module changes, such as converting release to getByName (“release”) and also converting minifyEnabled to isMinifyEnabled, as well as converting file tree to fileTree (Map args)!

STEP 6:

Create a buildSrc directory and create a Dependencies.kt file for all project landings!

You can create this file by right-clicking on the project name and selecting New Directory ‌ and selecting buildSrc.

Then create a directory in buildSrc called src. Then create another directory for src called main and then another directory for main called java.

Then in the java directory, create a Kotlin file called Dependencies.kt.

Dependencies.kt.

In this file, enter all the versions of your required. For example, in the project, we will have this file as follows :

Everything is very simple and clear and there is no need for additional explanation, so we will start the next step.

In the same buildSrc directory, create a file called build.gradle.kts and put this content in it without change and then sync the project.

Then go back to your gradle files and instead of the name of each dependency or its version, just use the class Dependencies.kt as follows:

and :

So now, by syncing, you will have an Android project with a Kotlin Gradle.

Finally, I put a video link for you on my YouTube channel and a complete project on Github Page.

Thanks for reading! And if you enjoyed it, gimme a clap .

Sana Ebadi | 11:06:11 PM Friday 10 April 2020

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Sana Ebadi
Sana Ebadi

Written by Sana Ebadi

Software Engineer | Trying to make a dream come true| sanaebadi.info

Responses (1)

Write a response