Migrate to Kotlin DSL

This commit is contained in:
Kirill Kamakin
2022-07-29 21:43:07 +02:00
parent 33bd8ba820
commit 8193db9498
8 changed files with 404 additions and 248 deletions

View File

@@ -1,204 +0,0 @@
plugins {
id("kotlin-android")
id("kotlin-kapt")
id("com.android.application")
id("androidx.navigation.safeargs.kotlin")
id("dagger.hilt.android.plugin")
id("org.jetbrains.kotlin.plugin.serialization")
id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
id("com.guardsquare.appsweep") version "$appsweep_version"
id("com.google.protobuf") version "$protobuf_plugin_version"
}
android {
compileSdk compile_sdk_version
defaultConfig {
applicationId "gq.kirmanak.mealient"
minSdk min_sdk_version
targetSdk target_sdk_version
versionCode 13
versionName "0.2.4"
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
buildConfigField "Boolean", "LOG_NETWORK", "false"
}
signingConfigs {
release {
rootProject.file("keystore.properties").with { keystorePropertiesFile ->
if (keystorePropertiesFile.canRead()) {
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
keyAlias keystoreProperties["keyAlias"]
keyPassword keystoreProperties["keyPassword"]
storeFile file(keystoreProperties["storeFile"])
storePassword keystoreProperties["storePassword"]
} else {
println "Unable to read keystore.properties"
}
}
}
}
buildTypes {
debug {
ext.enableCrashlytics = false
testCoverageEnabled true
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
buildFeatures {
viewBinding true
}
testOptions {
unitTests {
includeAndroidResources = true
all {
jacoco {
includeNoLocationClasses = true
excludes = ["jdk.internal.*"]
}
}
}
}
lint {
disable "ObsoleteLintCustomCheck", "IconMissingDensityFolder"
enable "ConvertToWebp", "DuplicateStrings", "EasterEgg", "ExpensiveAssertion", "IconExpectedSize", "ImplicitSamInstance", "InvalidPackage", "KotlinPropertyAccess", "LambdaLast", "MinSdkTooLow", "NegativeMargin", "NoHardKeywords", "Registered", "RequiredSize", "UnknownNullness", "WrongThreadInterprocedural"
}
namespace "gq.kirmanak.mealient"
packagingOptions {
resources.excludes += "DebugProbesKt.bin"
}
compileOptions {
coreLibraryDesugaringEnabled true
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:$desugar_version")
implementation("com.google.android.material:material:$material_version")
implementation("androidx.navigation:navigation-fragment-ktx:$nav_version")
implementation("androidx.navigation:navigation-runtime-ktx:$nav_version")
implementation("androidx.navigation:navigation-ui-ktx:$nav_version")
implementation("androidx.core:core-ktx:$core_ktx_version")
implementation("androidx.appcompat:appcompat:$appcompat_version")
implementation("androidx.constraintlayout:constraintlayout:$contraint_layout_version")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:$swipe_refresh_layout_version")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
implementation("com.google.dagger:hilt-android:$hilt_version")
kapt("com.google.dagger:hilt-compiler:$hilt_version")
kaptTest("com.google.dagger:hilt-android-compiler:$hilt_version")
testImplementation("com.google.dagger:hilt-android-testing:$hilt_version")
implementation("com.squareup.retrofit2:retrofit:$retrofit_version")
implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:$retrofit_kotlinx_serialization_version")
implementation platform("com.squareup.okhttp3:okhttp-bom:$okhttp_version")
implementation("com.squareup.okhttp3:okhttp")
debugImplementation("com.squareup.okhttp3:logging-interceptor")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinx_serialization_version")
implementation("com.jakewharton.timber:timber:$timber_version")
implementation("androidx.paging:paging-runtime-ktx:$paging_version")
testImplementation("androidx.paging:paging-common-ktx:$paging_version")
implementation("androidx.room:room-runtime:$room_version")
implementation("androidx.room:room-ktx:$room_version")
implementation("androidx.room:room-paging:$room_version")
kapt("androidx.room:room-compiler:$room_version")
testImplementation("androidx.room:room-testing:$room_version")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:$kotlinx_datetime_version")
implementation("com.github.bumptech.glide:glide:$glide_version")
implementation("com.github.bumptech.glide:okhttp3-integration:$glide_version")
implementation("com.github.bumptech.glide:recyclerview-integration:$glide_version") {
// Excludes the support library because it's already included by Glide.
transitive = false
}
kapt("com.github.bumptech.glide:compiler:$glide_version")
implementation("com.github.kirich1409:viewbindingpropertydelegate-noreflection:$view_binding_delegate_version")
implementation("androidx.datastore:datastore-preferences:$datastore_version")
implementation("androidx.datastore:datastore:$datastore_version")
implementation("com.google.protobuf:protobuf-javalite:$protobuf_version")
implementation("androidx.security:security-crypto:$security_version")
implementation platform("com.google.firebase:firebase-bom:$firebase_version")
implementation("com.google.firebase:firebase-analytics-ktx")
implementation("com.google.firebase:firebase-crashlytics-ktx")
testImplementation("junit:junit:$junit_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version")
testImplementation("org.robolectric:robolectric:$robolectric_version")
testImplementation("androidx.test.ext:junit-ktx:$junit_ktx_version")
testImplementation("com.google.truth:truth:$truth_version")
testImplementation("io.mockk:mockk:$mockk_version")
debugImplementation("com.squareup.leakcanary:leakcanary-android:$leakcanary_version")
// https://github.com/ChuckerTeam/chucker/releases
debugImplementation("com.github.chuckerteam.chucker:library:$chucker_version")
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:$protobuf_version"
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option "lite"
}
}
}
}
}

235
app/build.gradle.kts Normal file
View File

@@ -0,0 +1,235 @@
@file:Suppress("UnstableApiUsage")
import com.google.protobuf.gradle.builtins
import com.google.protobuf.gradle.generateProtoTasks
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.FileInputStream
import java.util.*
plugins {
id("kotlin-android")
id("kotlin-kapt")
id("com.android.application")
id("androidx.navigation.safeargs.kotlin")
id("dagger.hilt.android.plugin")
id("org.jetbrains.kotlin.plugin.serialization")
id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
id("com.guardsquare.appsweep") version Dependencies.appsweep_version
id("com.google.protobuf") version Dependencies.protobuf_plugin_version
}
android {
compileSdk = Dependencies.compile_sdk_version
defaultConfig {
applicationId = "gq.kirmanak.mealient"
minSdk = Dependencies.min_sdk_version
targetSdk = Dependencies.target_sdk_version
versionCode = 13
versionName = "0.2.4"
javaCompileOptions {
annotationProcessorOptions {
arguments += mapOf("room.schemaLocation" to "$projectDir/schemas")
}
}
buildConfigField("Boolean", "LOG_NETWORK", "false")
}
signingConfigs {
create("release") {
rootProject.file("keystore.properties").also { keystorePropertiesFile ->
if (keystorePropertiesFile.canRead()) {
val keystoreProperties = Properties()
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
keyAlias = keystoreProperties.getProperty("keyAlias")
keyPassword = keystoreProperties.getProperty("keyPassword")
storeFile = file(keystoreProperties.getProperty("storeFile"))
storePassword = keystoreProperties.getProperty("storePassword")
} else {
println("Unable to read keystore.properties")
}
}
}
}
buildTypes {
getByName("debug") {
ext["enableCrashlytics"] = false
isTestCoverageEnabled = true
}
getByName("release") {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("release")
}
}
buildFeatures {
viewBinding = true
}
testOptions {
unitTests {
isIncludeAndroidResources = true
}
}
lint {
disable += listOf("ObsoleteLintCustomCheck", "IconMissingDensityFolder")
enable += listOf(
"ConvertToWebp",
"DuplicateStrings",
"EasterEgg",
"ExpensiveAssertion",
"IconExpectedSize",
"ImplicitSamInstance",
"InvalidPackage",
"KotlinPropertyAccess",
"LambdaLast",
"MinSdkTooLow",
"NegativeMargin",
"NoHardKeywords",
"Registered",
"RequiredSize",
"UnknownNullness",
"WrongThreadInterprocedural"
)
}
namespace = "gq.kirmanak.mealient"
packagingOptions {
resources.excludes += "DebugProbesKt.bin"
}
compileOptions {
isCoreLibraryDesugaringEnabled = true
}
}
tasks.withType<Test>().configureEach {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-opt-in=kotlin.RequiresOptIn")
}
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:${Dependencies.desugar_version}")
implementation("com.google.android.material:material:${Dependencies.material_version}")
implementation("androidx.navigation:navigation-fragment-ktx:${Dependencies.nav_version}")
implementation("androidx.navigation:navigation-runtime-ktx:${Dependencies.nav_version}")
implementation("androidx.navigation:navigation-ui-ktx:${Dependencies.nav_version}")
implementation("androidx.core:core-ktx:${Dependencies.core_ktx_version}")
implementation("androidx.appcompat:appcompat:${Dependencies.appcompat_version}")
implementation("androidx.constraintlayout:constraintlayout:${Dependencies.contraint_layout_version}")
implementation("androidx.swiperefreshlayout:swiperefreshlayout:${Dependencies.swipe_refresh_layout_version}")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:${Dependencies.lifecycle_version}")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:${Dependencies.lifecycle_version}")
implementation("com.google.dagger:hilt-android:${Dependencies.hilt_version}")
kapt("com.google.dagger:hilt-compiler:${Dependencies.hilt_version}")
kaptTest("com.google.dagger:hilt-android-compiler:${Dependencies.hilt_version}")
testImplementation("com.google.dagger:hilt-android-testing:${Dependencies.hilt_version}")
implementation("com.squareup.retrofit2:retrofit:${Dependencies.retrofit_version}")
implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:${Dependencies.retrofit_kotlinx_serialization_version}")
implementation(platform("com.squareup.okhttp3:okhttp-bom:${Dependencies.okhttp_version}"))
implementation("com.squareup.okhttp3:okhttp")
debugImplementation("com.squareup.okhttp3:logging-interceptor")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:${Dependencies.kotlinx_serialization_version}")
implementation("com.jakewharton.timber:timber:${Dependencies.timber_version}")
implementation("androidx.paging:paging-runtime-ktx:${Dependencies.paging_version}")
testImplementation("androidx.paging:paging-common-ktx:${Dependencies.paging_version}")
implementation("androidx.room:room-runtime:${Dependencies.room_version}")
implementation("androidx.room:room-ktx:${Dependencies.room_version}")
implementation("androidx.room:room-paging:${Dependencies.room_version}")
kapt("androidx.room:room-compiler:${Dependencies.room_version}")
testImplementation("androidx.room:room-testing:${Dependencies.room_version}")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:${Dependencies.kotlinx_datetime_version}")
implementation("com.github.bumptech.glide:glide:${Dependencies.glide_version}")
implementation("com.github.bumptech.glide:okhttp3-integration:${Dependencies.glide_version}")
implementation("com.github.bumptech.glide:recyclerview-integration:${Dependencies.glide_version}") {
// Excludes the support library because it's already included by Glide.
isTransitive = false
}
kapt("com.github.bumptech.glide:compiler:${Dependencies.glide_version}")
implementation("com.github.kirich1409:viewbindingpropertydelegate-noreflection:${Dependencies.view_binding_delegate_version}")
implementation("androidx.datastore:datastore-preferences:${Dependencies.datastore_version}")
implementation("androidx.datastore:datastore:${Dependencies.datastore_version}")
implementation("com.google.protobuf:protobuf-javalite:${Dependencies.protobuf_version}")
implementation("androidx.security:security-crypto:${Dependencies.security_version}")
implementation(platform("com.google.firebase:firebase-bom:${Dependencies.firebase_version}"))
implementation("com.google.firebase:firebase-analytics-ktx")
implementation("com.google.firebase:firebase-crashlytics-ktx")
testImplementation("junit:junit:${Dependencies.junit_version}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${Dependencies.coroutines_version}")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Dependencies.coroutines_version}")
testImplementation("org.robolectric:robolectric:${Dependencies.robolectric_version}")
testImplementation("androidx.test.ext:junit-ktx:${Dependencies.junit_ktx_version}")
testImplementation("com.google.truth:truth:${Dependencies.truth_version}")
testImplementation("io.mockk:mockk:${Dependencies.mockk_version}")
debugImplementation("com.squareup.leakcanary:leakcanary-android:${Dependencies.leakcanary_version}")
// https://github.com/ChuckerTeam/chucker/releases
debugImplementation("com.github.chuckerteam.chucker:library:${Dependencies.chucker_version}")
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${Dependencies.protobuf_version}"
}
generateProtoTasks {
all().forEach { task ->
task.builtins {
val java by registering {
option("lite")
}
}
}
}
}

View File

@@ -1,44 +0,0 @@
buildscript {
apply {
from "./gradle/versions.gradle"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:$android_plugin_version")
classpath("com.google.gms:google-services:$google_services_version")
classpath("com.google.firebase:firebase-crashlytics-gradle:$crashlytics_version")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlin_version")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
classpath("com.google.dagger:hilt-android-gradle-plugin:$hilt_version")
}
}
plugins {
id("org.sonarqube") version "$sonarqube_version"
id("nl.neotech.plugin.rootcoverage") version "$root_coverage_version"
}
task clean(type: Delete) {
delete rootProject.buildDir
}
sonarqube {
properties {
property "sonar.projectKey", "kirmanak_Mealient"
property "sonar.organization", "kirmanak"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.androidLint.reportPaths", "build/reports/lint-results-debug.xml"
property "sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco.xml"
}
}
rootCoverage {
generateXml true
}

37
build.gradle.kts Normal file
View File

@@ -0,0 +1,37 @@
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:${Dependencies.android_plugin_version}")
classpath("com.google.gms:google-services:${Dependencies.google_services_version}")
classpath("com.google.firebase:firebase-crashlytics-gradle:${Dependencies.crashlytics_version}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Dependencies.kotlin_version}")
classpath("org.jetbrains.kotlin:kotlin-serialization:${Dependencies.kotlin_version}")
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:${Dependencies.nav_version}")
classpath("com.google.dagger:hilt-android-gradle-plugin:${Dependencies.hilt_version}")
}
}
plugins {
id("org.sonarqube") version "${Dependencies.sonarqube_version}"
id("nl.neotech.plugin.rootcoverage") version "${Dependencies.root_coverage_version}"
kotlin("jvm") version "1.7.10"
}
sonarqube {
properties {
property("sonar.projectKey", "kirmanak_Mealient")
property("sonar.organization", "kirmanak")
property("sonar.host.url", "https://sonarcloud.io")
property("sonar.androidLint.reportPaths", "build/reports/lint-results-debug.xml")
property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco.xml")
}
}
rootCoverage {
generateXml = true
}

1
buildSrc/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,7 @@
repositories {
mavenCentral()
}
plugins {
`kotlin-dsl`
}

View File

@@ -0,0 +1,122 @@
object Dependencies {
// https://github.com/protocolbuffers/protobuf/releases
const val protobuf_version = "3.21.2"
// https://github.com/google/protobuf-gradle-plugin/releases
const val protobuf_plugin_version = "0.8.19"
// https://developer.android.com/jetpack/androidx/releases/navigation
const val nav_version = "2.5.0"
// https://dagger.dev/hilt/gradle-setup
const val hilt_version = "2.42"
// https://kotlinlang.org/docs/gradle.html
const val kotlin_version = "1.6.10"
// https://maven.google.com/web/index.html?q=com.android.tools.build#com.android.tools.build:gradle
const val android_plugin_version = "7.2.1"
// https://developers.google.com/android/guides/google-services-plugin
const val google_services_version = "4.3.13"
// https://mvnrepository.com/artifact/com.google.firebase/firebase-crashlytics-gradle
const val crashlytics_version = "2.9.1"
// https://plugins.gradle.org/plugin/org.sonarqube
const val sonarqube_version = "3.4.0.2513"
// https://plugins.gradle.org/plugin/nl.neotech.plugin.rootcoverage
const val root_coverage_version = "1.5.3"
// https://plugins.gradle.org/plugin/com.guardsquare.appsweep
const val appsweep_version = "1.1.0"
const val compile_sdk_version = 32
const val min_sdk_version = 23
const val target_sdk_version = 32
// https://github.com/material-components/material-components-android/releases
const val material_version = "1.6.1"
// https://developer.android.com/kotlin/ktx#core
const val core_ktx_version = "1.8.0"
// https://developer.android.com/jetpack/androidx/releases/appcompat
const val appcompat_version = "1.4.2"
// https://developer.android.com/jetpack/androidx/releases/constraintlayout
const val contraint_layout_version = "2.1.4"
// https://developer.android.com/jetpack/androidx/releases/swiperefreshlayout
const val swipe_refresh_layout_version = "1.1.0"
// https://developer.android.com/jetpack/androidx/releases/lifecycle
const val lifecycle_version = "2.5.0"
// https://github.com/square/retrofit/tags
const val retrofit_version = "2.9.0"
// https://github.com/JakeWharton/retrofit2-kotlinx-serialization-converter/tags
const val retrofit_kotlinx_serialization_version = "0.8.0"
// https://github.com/Kotlin/kotlinx.serialization/releases
const val kotlinx_serialization_version = "1.3.3"
// https://github.com/square/okhttp/tags
const val okhttp_version = "4.10.0"
// https://github.com/JakeWharton/timber/releases
const val timber_version = "5.0.1"
// https://developer.android.com/jetpack/androidx/releases/paging
const val paging_version = "3.1.1"
// https://developer.android.com/jetpack/androidx/releases/room
const val room_version = "2.4.2"
// https://github.com/Kotlin/kotlinx-datetime/releases
const val kotlinx_datetime_version = "0.4.0"
// https://github.com/bumptech/glide/releases
const val glide_version = "4.13.2"
// https://github.com/androidbroadcast/ViewBindingPropertyDelegate/releases
const val view_binding_delegate_version = "1.5.6"
// https://developer.android.com/jetpack/androidx/releases/datastore
const val datastore_version = "1.0.0"
// https://developer.android.com/jetpack/androidx/releases/security
const val security_version = "1.0.0"
// https://mvnrepository.com/artifact/com.google.firebase/firebase-bom?repo=google
const val firebase_version = "30.2.0"
// https://github.com/junit-team/junit4/releases
const val junit_version = "4.13.2"
// https://developer.android.com/jetpack/androidx/releases/test
const val junit_ktx_version = "1.1.3"
// https://github.com/Kotlin/kotlinx.coroutines/releases
const val coroutines_version = "1.6.3"
// https://github.com/robolectric/robolectric/releases
const val robolectric_version = "4.8.1"
// https://mvnrepository.com/artifact/com.google.truth/truth
const val truth_version = "1.1.3"
// https://mockk.io/
const val mockk_version = "1.12.4"
// https://github.com/square/leakcanary/releases
const val leakcanary_version = "2.9.1"
// https://github.com/ChuckerTeam/chucker/releases
const val chucker_version = "3.5.2"
// https://developer.android.com/studio/write/java8-support#library-desugaring
const val desugar_version = "1.1.5"
}

View File

@@ -1,3 +1,5 @@
@file:Suppress("UnstableApiUsage")
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {