Giter VIP home page Giter VIP logo

gradlekotlinconverter's Introduction

Image of GradleKotlinConverter

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 (brew install kotlin or scoop install kotlin -g on windows with Scoop).

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:

GIF

๐Ÿ˜ฑ 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")

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.

gradlekotlinconverter's People

Contributors

arberg avatar bernaferrari avatar code-schreiber avatar imgbotapp avatar jasonjoneski avatar mherod avatar pavi2410 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.