Skip to content

bernaferrari/GradleKotlinConverter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image of GradleKotlinConverter

Gradle Kotlin DSL Converter

A powerful tool to simplify the migration from Gradle's Groovy DSL to Kotlin DSL for Android projects.

Image of website

Visit https://gradle-kotlin-converter.vercel.app/ to use the converter.

Overview

The Gradle Kotlin DSL Converter is designed to streamline the process of transitioning from Gradle's Groovy DSL to Kotlin DSL in Android Studio. This tool automates many of the repetitive tasks involved in the migration, significantly reducing the time and effort required to update your build scripts.

While it may not produce a perfect conversion in all cases, it serves as an invaluable first step in the migration process, similar to Android Studio's Java to Kotlin converter.

Features

  • Converts Groovy-style Gradle scripts to Kotlin DSL format
  • Handles common syntax differences and idiomatic changes
  • Supports both file-based and clipboard-based conversion
  • Addresses numerous edge cases and common migration challenges

Getting Started

Web Interface

Visit our web-based converter for an easy-to-use interface that doesn't require any local setup.

Conversion Capabilities

The converter handles a wide range of Gradle script elements, including:

  • String delimiter conversion (apostrophes to quotation marks)
  • Variable declaration updates (def to val)
  • Plugin application syntax
  • Dependency declaration format
  • Repository and Maven configurations
  • SDK version and build type declarations
  • ProGuard file configurations
  • Kotlin-specific dependency declarations
  • And more:

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")
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")

You can find all the details on the source code.

The script was made to convert build.gradle in build.gradle.kts, but it can also help in the migration if you paste something that is not in Kotlin DSL format and you want it converted. If you paste something like a implementation '...' and want it converted to implementation("..."), you are free to call the script on build.gradle.kts file and see it working as expected.

When applying on build.gradle, the script will create, for example, build.gradle.kts. When applying on a file that already ends in .kts, the script will overrite the file. In that case, please make sure you are using git or have a backup, in case things turn out wrong.

Things it still can't do

  • If you find anything, just tell me.

Issue Tracking

Found a bug? Have an idea for an improvement? Feel free to add an issue.

License

Copyright 2018 Bernardo Ferrari.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.