• Stars
    star
    916
  • Rank 49,875 (Top 1.0 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convert from Groovy to Kotlin DSL for Gradle, focused on Android.

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

More Repositories

1

FigmaToCode

Generate responsive pages and apps on HTML, Tailwind, Flutter and SwiftUI.
TypeScript
3,725
star
2

ChangeDetection

Automatically track websites changes on Android in background.
Kotlin
704
star
3

EmojiSlider

🤯 A slider widget rich in emoji and highly customisable.
Kotlin
600
star
4

color-studio

It is too hard to build coherent and accessible themes with the right colors. This should help.
Dart
418
star
5

SDKMonitor

App to display and monitor the targetSDK from installed apps.
Kotlin
131
star
6

CashBalancer

It is too hard to balance money across different assets and accounts.
Dart
79
star
7

RandomColorScheme

Flutter plugin to help experiment with different Color Schemes without pain.
Dart
77
star
8

ColorBlindnessFlutter

Simulate color blindness in color themes.
Dart
59
star
9

hsluv-dart

Dart port of HSLuv, a human-friendly alternative to HSL based on human experiments.
Dart
51
star
10

FastDarkTheme

Experiment with dark themes based on popular apps.
Dart
48
star
11

SafeChangeLog

Make sure your changelogs are safe in all devices.
Rust
40
star
12

CarouselGifViewer

Efficiently display a list of GIFs in a carousel (RecyclerView).
Kotlin
36
star
13

FlutterResourceRanker

Find underused colors, overused magical numbers and the largest classes in any Flutter project.
Kotlin
23
star
14

non_uniform_border

Provides a border class for Flutter that allows different widths for each side with a single color.
Dart
22
star
15

current-setup

My current terminal config, .zshrc file and brew apps list.
Shell
5
star
16

RegexLearner

A journey through the world with regular expressions. Swift Student Challenge (WWDC20) winner.
Swift
3
star
17

material-color-utilities-mojo

Dart
3
star
18

MultiModule

Temporary project
Kotlin
1
star
19

covid19-br

JavaScript
1
star
20

bernaferrari.github.io

A quick showcase of my projects (that were compiled for the web).
JavaScript
1
star