Skip to content

Commit

Permalink
Migrate to Kotlin DSL (#2490)
Browse files Browse the repository at this point in the history
Co-authored-by: Mygod <[email protected]>
  • Loading branch information
onlymash and Mygod authored Apr 21, 2020
1 parent 141a307 commit 990b693
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 376 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
- checkout
- run: git submodule update --init --recursive
- restore_cache:
key: jars-{{ checksum "build.gradle" }}
key: jars-{{ checksum "build.gradle.kts" }}
- run:
name: Run Build and Tests
command: ./gradlew assembleDebug check -PCARGO_PROFILE=debug
- save_cache:
paths:
- ~/.gradle
- ~/.android/build-cache
key: jars-{{ checksum "build.gradle" }}
key: jars-{{ checksum "build.gradle.kts" }}
- store_artifacts:
path: mobile/build/outputs/apk
destination: apk/mobile
Expand Down
51 changes: 0 additions & 51 deletions build.gradle

This file was deleted.

33 changes: 33 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

plugins {
id("com.github.ben-manes.versions") version "0.28.0"
}

buildscript {
apply(from = "repositories.gradle.kts")

repositories {
google()
jcenter()
maven("https://plugins.gradle.org/m2/")
}

dependencies {
classpath(rootProject.extra.get("androidPlugin").toString())
classpath(kotlin("gradle-plugin", rootProject.extra.get("kotlinVersion").toString()))
classpath("com.google.android.gms:oss-licenses-plugin:0.10.2")
classpath("com.google.firebase:firebase-crashlytics-gradle:2.0.0-beta04")
classpath("com.google.gms:google-services:4.3.3")
classpath("com.vanniktech:gradle-maven-publish-plugin:0.11.1")
classpath("gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3")
}
}

allprojects {
apply(from = "${rootProject.projectDir}/repositories.gradle.kts")
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
10 changes: 10 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
`kotlin-dsl`
}

apply(from = "../repositories.gradle.kts")

dependencies {
implementation(rootProject.extra.get("androidPlugin").toString())
implementation(kotlin("gradle-plugin", rootProject.extra.get("kotlinVersion").toString()))
}
95 changes: 95 additions & 0 deletions buildSrc/src/main/kotlin/Helpers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

import com.android.build.VariantOutput
import com.android.build.gradle.AbstractAppExtension
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.internal.api.ApkVariantOutputImpl
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByName
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
import java.util.*

const val lifecycleVersion = "2.2.0"

private val Project.android get() = extensions.getByName<BaseExtension>("android")

private val flavorRegex = "(assemble|generate)\\w*(Release|Debug)".toRegex()
val Project.currentFlavor get() = gradle.startParameter.taskRequests.toString().let { task ->
flavorRegex.matchEntire(task)?.groupValues?.get(2)?.toLowerCase(Locale.ROOT) ?: "debug".also {
println("Warning: No match found for $task")
}
}

fun Project.setupCommon() {
android.apply {
compileSdkVersion(29)
defaultConfig {
minSdkVersion(21)
targetSdkVersion(29)
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
val javaVersion = JavaVersion.VERSION_1_8
compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
(this as ExtensionAware).extensions.getByName<KotlinJvmOptions>("kotlinOptions").jvmTarget =
javaVersion.toString()
}

dependencies {
add("testImplementation", "junit:junit:4.13")
add("androidTestImplementation", "androidx.test:runner:1.2.0")
add("androidTestImplementation", "androidx.test.espresso:espresso-core:3.2.0")
}
}

fun Project.setupCore() {
setupCommon()
android.apply {
defaultConfig {
versionCode = 5000650
versionName = "5.0.6-nightly"
}
compileOptions.isCoreLibraryDesugaringEnabled = true
}
dependencies.add("coreLibraryDesugaring", "com.android.tools:desugar_jdk_libs:1.0.5")
}

private val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86" to 3, "x86_64" to 4)
fun Project.setupApp() {
setupCore()

android.apply {
defaultConfig.resConfigs(listOf("ar", "es", "fa", "fr", "ja", "ko", "ru", "tr", "zh-rCN", "zh-rTW"))
buildTypes {
getByName("debug") {
isPseudoLocalesEnabled = true
}
getByName("release") {
isShrinkResources = true
isMinifyEnabled = true
proguardFile(getDefaultProguardFile("proguard-android.txt"))
}
}
packagingOptions {
exclude("**/*.kotlin_*")
}
splits.abi {
isEnable = true
isUniversalApk = true
}
}

dependencies.add("implementation", project(":core"))

if (currentFlavor == "release") (android as AbstractAppExtension).applicationVariants.all {
for (output in outputs) {
abiCodes[(output as ApkVariantOutputImpl).getFilter(VariantOutput.ABI)]?.let { offset ->
output.versionCodeOverride = versionCode + offset
}
}
}
}
101 changes: 0 additions & 101 deletions core/build.gradle

This file was deleted.

Loading

0 comments on commit 990b693

Please sign in to comment.