# GradleKotlinConverter **Repository Path**: RealHeart/GradleKotlinConverter ## Basic Information - **Project Name**: GradleKotlinConverter - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-10-23 - **Last Updated**: 2021-06-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README  Gradle Kotlin DSL converter ================= Welcome! After a lot of pain trying to migrate from Gradle's Groovy to Kotlin DSL on Android Studio, I developed this tool to solve most migration issues and reduce the amount of work you need in order to make things ready. Please see this tool as a helper, a first resource like Android Studio's Java converter to Kotlin: it won't make a _perfect_ conversion, but it helps a lot in reducing the time you would spend on repetitive tasks. 💻 Getting Started --------------- The script was written in Kotlin and depends on JVM (for File access). If you need to install Kotlin for command line access, [check here](https://kotlinlang.org/docs/tutorials/command-line.html) (`brew install kotlin` or `scoop install kotlin -g` on windows with [Scoop](https://scoop.sh/)). ``` File mode: $ ./gradlekotlinconverter.kts build.gradle $ kotlinc -script gradlekotlinconverter.kts build.gradle Clipboard mode: $ ./gradlekotlinconverter.kts ``` **Motivation**: on my own apps, I've used apostrophes \' instead of quotation marks \" since forever, so it wasn't fun when I discovered I would need to modify more than 100 lines of code to make Kotlin DSL work. Besides this, the tool also solves a few common issues that might appear, like the ```task clean(type: Delete)``` that becomes a completely different thing. 📋 Clipboard mode --------------- Sometimes you just want to copy and paste. Just copy whatever you want, run the script, then paste on your IDE. The GIF showcases how simple it is:  😱 Things it can do ---------------
| Description | Before | After |
|---|---|---|
| Replace all ' with " | 'kotlin-android' | "kotlin-android" |
| Replace "def " with "val " | def appcompat = "1.0.0" | val appcompat = "1.0.0" |
| Convert plugins | apply plugin: "kotlin-kapt" | apply(plugin = "kotlin-kapt") |
| Add ( ) to dependencies | implementation ":epoxy" | implementation(":epoxy") |
| Convert Maven | maven { url "https://jitpack.io" } | maven("https://jitpack.io") |
| Convert Sdk Version | compileSdkVersion 28 | compileSdkVersion(28) |
| Convert Version Code | versionCode 4 | versionCode = 4 |
| Convert Build Types | debuggable true | isDebuggable = true |
| Convert proguardFiles | proguardFiles getDef..., "..." | setProguardFiles(listOf(getDef..., "...") |
| Convert sourceCompatibility | sourceCompatibility = "1.8" | sourceCompatibility = JavaVersion.VERSION_1_8 |
| Convert androidExtensions | androidExtensions { experimental = true } | androidExtensions { isExperimental = true } |
| Convert include | include ":app", ":diffutils" | include(":app", ":diffutils") |
| Convert signingConfigs | signingConfigs { debug { ... } } | signingConfigs { register("debug") { ... } } |
| Convert buildTypes | buildTypes { debug { ... } } | buildTypes { named("debug") { ... } }) |
| Convert classpath.exclude | configurations.classpath.exclude group: '...lombok' | configurations.classpath { exclude(group = "...lombok") } |
| Kt dependencies (1/3) | "org.jetbrains.kotlin:kotlin-gradle-plugin:$kt_v" | kotlin("gradle-plugin", version = "$kt_v") |
| Kt dependencies (2/3) | "org.jetbrains.kotlin:kotlin-stdlib:$kt_v" | kotlin("stdlib", KotlinCompilerVersion.VERSION) |
| Kt dependencies (3/3) | "org.jetbrains.kotlin:kotlin-reflect" | kotlin("reflect") |
| Convert signingConfig | signingConfig signingConfigs.release | signingConfig = signingConfigs.getByName("release") |
| Convert extras | ext.enableCrashlytics = false | extra.set("enableCrashlytics", false) |
| Convert plugins | apply(...) apply(...) | plugins { id(...) id(...) } |
| Convert plugin ids | id "io.gitlab.arturbosch.detekt" version "1.0" | id("io.gitlab.arturbosch.detekt") version "1.0" |
| Convert ":" to " =" | testImpl(name: "junit", version: "4.12") | testImpl(name = "junit", version = "4.12") |