From 943d564c0ffec0b98b690d33eb6bc0863baf9783 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 27 Sep 2023 14:52:36 +0200 Subject: [PATCH] gradle -> kts --- app/build.gradle | 2 - app/build.gradle.kts | 225 +++++++++++++++++++++++++++ build.gradle | 126 --------------- build.gradle.kts | 117 ++++++++++++++ buildSrc/build.gradle.kts | 7 + buildSrc/src/main/kotlin/Libs.kt | 69 ++++++++ buildSrc/src/main/kotlin/Versions.kt | 7 + core/graphview/build.gradle | 17 -- core/graphview/build.gradle.kts | 17 ++ 9 files changed, 442 insertions(+), 145 deletions(-) create mode 100644 app/build.gradle.kts delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/Libs.kt create mode 100644 buildSrc/src/main/kotlin/Versions.kt delete mode 100644 core/graphview/build.gradle create mode 100644 core/graphview/build.gradle.kts diff --git a/app/build.gradle b/app/build.gradle index e97d45c945..776643a033 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,6 @@ plugins { id 'kotlinx-serialization' id 'com.google.gms.google-services' id 'com.google.firebase.crashlytics' - id 'com.vanniktech.dependency.graph.generator' - } apply from: "${project.rootDir}/core/main/android_dependencies.gradle" diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000000..34cf8a4212 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,225 @@ +import java.io.ByteArrayOutputStream +import java.text.SimpleDateFormat +import java.util.Date +import kotlin.io.println + +plugins { + id("com.android.application") + id("kotlin-android") + id("kotlin-kapt") + id("kotlin-allopen") + id("kotlinx-serialization") + id("com.google.gms.google-services") + id("com.google.firebase.crashlytics") +} + +apply(from = "${project.rootDir}/core/main/android_dependencies.gradle") +apply(from = "${project.rootDir}/core/main/jacoco_global.gradle") + +repositories { + mavenCentral() + google() +} + +allOpen { + // allows mocking for classes w/o directly opening them for release builds + annotation("info.nightscout.androidaps.annotations.OpenForTesting") +} + +fun generateGitBuild(): String = + try { + ByteArrayOutputStream().let { + exec { + commandLine("git", "describe", "--always") + standardOutput = it + } + it.toString().trim() + } + } catch (ignored: Exception) { + "NoGitSystemAvailable" + } + +fun generateGitRemote(): String = + try { + ByteArrayOutputStream().let { + exec { + commandLine("git", "remote", "get-url", "origin") + standardOutput = it + } + it.toString().trim() + } + } catch (ignored: Exception) { + "NoGitSystemAvailable" + } + +fun generateDate(): String = + // showing only date prevents app to rebuild everytime + SimpleDateFormat("yyyy.MM.dd").format(Date()) + +fun isMaster(): Boolean = !Versions.appVersion.contains("-") + +fun gitAvailable(): Boolean = + try { + ByteArrayOutputStream().let { + exec { + commandLine("git", "--version") + standardOutput = it + } + it.toString().trim().isNotEmpty() + } + } catch (ignored: Exception) { + false // NoGitSystemAvailable + } + +fun allCommitted(): Boolean = + try { + ByteArrayOutputStream().let { + exec { + commandLine("git", "status", "-s") + standardOutput = it + } + it.toString() + // ignore all changes done in .idea/codeStyles + .replace(Regex("(?m)^\\s*(M|A|D|\\?\\?)\\s*.*?\\.idea\\/codeStyles\\/.*?\\s*$"), "") + // ignore all files added to project dir but not staged/known to GIT + .replace(Regex("(?m)^\\s*(\\?\\?)\\s*.*?\\s*$"), "") + .trim().isEmpty() + } + } catch (ignored: Exception) { + false // NoGitSystemAvailable + } + +android { + + namespace = "info.nightscout.androidaps" + ndkVersion = Versions.ndkVersion + + defaultConfig { + multiDexEnabled = true + versionCode = Versions.versionCode + version = Versions.appVersion + buildConfigField("String", "VERSION", "\"" + Versions.appVersion + "\"") + buildConfigField("String", "BUILDVERSION", "\"" + generateGitBuild() + "-" + generateDate() + "\"") + buildConfigField("String", "REMOTE", "\"" + generateGitRemote() + "\"") + buildConfigField("String", "HEAD", "\"" + generateGitBuild() + "\"") + buildConfigField("Boolean", "COMMITTED", allCommitted().toString()) + } + + val dim = "standard" + flavorDimensions.add(dim) + productFlavors { + create("full") { + applicationId = "info.nightscout.androidaps" + dimension = dim + resValue("string", "app_name", "AAPS") + versionName = Versions.appVersion + manifestPlaceholders["appIcon"] = "@mipmap/ic_launcher" + manifestPlaceholders["appIconRound"] = "@mipmap/ic_launcher_round" + } + create("pumpcontrol") { + applicationId = "info.nightscout.aapspumpcontrol" + dimension = dim + resValue("string", "app_name", "Pumpcontrol") + versionName = Versions.appVersion + "-pumpcontrol" + manifestPlaceholders["appIcon"] = "@mipmap/ic_pumpcontrol" + manifestPlaceholders["appIconRound"] = "@null" + } + create("aapsclient") { + applicationId = "info.nightscout.aapsclient" + dimension = dim + resValue("string", "app_name", "AAPSClient") + versionName = Versions.appVersion + "-aapsclient" + manifestPlaceholders["appIcon"] = "@mipmap/ic_yellowowl" + manifestPlaceholders["appIconRound"] = "@mipmap/ic_yellowowl" + } + create("aapsclient2") { + applicationId = "info.nightscout.aapsclient2" + dimension = dim + resValue("string", "app_name", "AAPSClient2") + versionName = Versions.appVersion + "-aapsclient" + manifestPlaceholders["appIcon"] = "@mipmap/ic_blueowl" + manifestPlaceholders["appIconRound"] = "@mipmap/ic_blueowl" + } + } + + dataBinding { //Deleting it causes a binding error + enable = true + } +} + +dependencies { + // in order to use internet"s versions you"d need to enable Jetifier again + // https://github.com/nightscout/graphview.git + // https://github.com/nightscout/iconify.git + implementation(project(":app-wear-shared:shared")) + implementation(project(":app-wear-shared:shared-impl")) + implementation(project(":core:main")) + implementation(project(":core:graph")) + implementation(project(":core:graphview")) + implementation(project(":core:interfaces")) + implementation(project(":core:libraries")) + implementation(project(":core:ns-sdk")) + implementation(project(":core:utils")) + implementation(project(":core:ui")) + implementation(project(":core:validators")) + implementation(project(":ui")) + implementation(project(":plugins:aps")) + implementation(project(":plugins:automation")) + implementation(project(":plugins:configuration")) + implementation(project(":plugins:constraints")) + implementation(project(":plugins:insulin")) + implementation(project(":plugins:main")) + implementation(project(":plugins:sensitivity")) + implementation(project(":plugins:smoothing")) + implementation(project(":plugins:source")) + implementation(project(":plugins:sync")) + implementation(project(":implementation")) + implementation(project(":database:entities")) + implementation(project(":database:impl")) + implementation(project(":pump:combo")) + implementation(project(":pump:combov2")) + implementation(project(":pump:dana")) + implementation(project(":pump:danars")) + implementation(project(":pump:danar")) + implementation(project(":pump:diaconn")) + implementation(project(":pump:eopatch")) + implementation(project(":pump:medtrum")) + implementation(project(":insight")) + implementation(project(":pump:medtronic")) + implementation(project(":pump:pump-common")) + implementation(project(":pump:pump-core")) + implementation(project(":pump:omnipod-common")) + implementation(project(":pump:omnipod-eros")) + implementation(project(":pump:omnipod-dash")) + implementation(project(":pump:rileylink")) + implementation(project(":pump:virtual")) + implementation(project(":workflow")) + + testImplementation(project(":app-wear-shared:shared-tests")) + + //implementation fileTree(include = listOf("*.jar"), dir = "libs") + + /* Dagger2 - We are going to use dagger.android which includes + * support for Activity and fragment injection so we need to include + * the following dependencies */ + kapt(Libs.Dagger.androidProcesssor) + kapt(Libs.Dagger.compiler) + + // MainApp + api(Libs.Rx.rxDogTag) + +} + +apply(from = "${project.rootDir}/core/main/test_dependencies.gradle") + +println("--------------") +println("isMaster: ${isMaster()}") +println("gitAvailable: ${gitAvailable()}") +println("allCommitted: ${allCommitted()}") +println("--------------") +if (isMaster() && !gitAvailable()) { + throw GradleException("GIT system is not available. On Windows try to run Android Studio as an Administrator. Check if GIT is installed and Studio have permissions to use it") +} +if (isMaster() && !allCommitted()) { + throw GradleException("There are uncommitted changes. Clone sources again as described in wiki and do not allow gradle update") +} diff --git a/build.gradle b/build.gradle deleted file mode 100644 index e42f6b01a7..0000000000 --- a/build.gradle +++ /dev/null @@ -1,126 +0,0 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -// Top-level build file where you can add configuration options common to all sub-projects/modules. - -buildscript { - ext { - kotlin_version = '1.9.10' - core_version = '1.12.0' - rxjava_version = '3.1.7' - rxandroid_version = '3.0.2' - rxkotlin_version = '3.0.1' - room_version = '2.5.2' - lifecycle_version = '2.6.2' - dagger_version = '2.48' - coroutines_version = '1.7.3' - activity_version = '1.7.2' - fragmentktx_version = '1.6.1' - ormLite_version = '4.46' - gson_version = '2.10.1' - nav_version = '2.7.3' - appcompat_version = '1.6.1' - material_version = '1.9.0' - gridlayout_version = '1.0.0' - constraintlayout_version = '2.1.4' - preferencektx_version = '1.2.1' - commonslang3_version = '3.13.0' - commonscodec_version = '1.16.0' - guava_version = '32.1.2-jre' - jodatime_version = '2.12.5' - work_version = '2.8.1' - tink_version = '1.10.0' - json_version = '20230618' - joda_version = '2.12.5' - swipe_version = '1.1.0' - - junit_version = '4.13.2' - junit_jupiter_version = '5.10.0' - mockito_version = '5.5.0' - dexmaker_version = '1.2' - retrofit2_version = '2.9.0' - okhttp3_version = '4.11.0' - byteBuddy_version = '1.12.8' - - androidx_junit_version = '1.1.5' - androidx_rules_version = '1.5.0' - - rxandroidble_version = '1.12.1' - replayshare_version = '2.2.0' - - wearable_version = '2.9.0' - play_services_wearable_version = '18.1.0' - play_services_location_version = '21.0.1' - play_services_measurement_version = '21.3.0' - - kotlinx_datetime_version = '0.4.1' - kotlinx_serialization_version = '1.6.0' - - caverock_androidsvg_version = '1.4' - } - repositories { - google() - mavenCentral() - } - dependencies { - classpath 'com.android.tools.build:gradle:8.1.1' - classpath 'com.google.gms:google-services:4.4.0' - classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" - classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" - classpath "org.jacoco:org.jacoco.core:0.8.10" - classpath "com.vanniktech:gradle-dependency-graph-generator-plugin:0.8.0" - } -} - -plugins { - // Test Gradle build, keep disabled under normal circumstances - // id "com.osacky.doctor" version "0.8.1" - id "org.jlleitschuh.gradle.ktlint" version "11.6.0" - // Aggregates and/or logs Jacoco test coverage to the Gradle build log - //id 'org.barfuin.gradle.jacocolog' version '3.1.0' - id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false -} - -allprojects { - repositories { - google() - mavenCentral() - maven { url "https://maven.google.com" } - maven { url 'https://jitpack.io' } - } - tasks.withType(KotlinCompile).all { - kotlinOptions { - freeCompilerArgs = [ - '-opt-in=kotlin.RequiresOptIn', - '-Xjvm-default=all' //Support @JvmDefault - ] - jvmTarget = "11" - } - } - gradle.projectsEvaluated { - tasks.withType(JavaCompile) { - options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" - } - } - - apply plugin: 'org.jlleitschuh.gradle.ktlint' - apply plugin: 'jacoco' -} - -// Setup all al reports aggregation -apply from: 'jacoco_project.gradle' - -task clean(type: Delete) { - delete rootProject.buildDir -} - -subprojects { - tasks.withType(Test) { - maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000000..33ca1efc5d --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,117 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + // extra is duplicated to Versions here until full migration to kts + extra.apply { + set("kotlin_version", "1.9.10") + set("core_version", "1.12.0") + set("rxjava_version", "3.1.7") + set("rxandroid_version", "3.0.2") + set("rxkotlin_version", "3.0.1") + set("room_version", "2.5.2") + set("lifecycle_version", "2.6.2") + set("dagger_version", "2.48") + set("coroutines_version", "1.7.3") + set("activity_version", "1.7.2") + set("fragmentktx_version", "1.6.1") + set("ormLite_version", "4.46") + set("gson_version", "2.10.1") + set("nav_version", "2.7.3") + set("appcompat_version", "1.6.1") + set("material_version", "1.9.0") + set("gridlayout_version", "1.0.0") + set("constraintlayout_version", "2.1.4") + set("preferencektx_version", "1.2.1") + set("commonslang3_version", "3.13.0") + set("commonscodec_version", "1.16.0") + set("guava_version", "32.1.2-jre") + set("jodatime_version", "2.12.5") + set("work_version", "2.8.1") + set("tink_version", "1.10.0") + set("json_version", "20230618") + set("joda_version", "2.12.5") + set("swipe_version", "1.1.0") + + set("junit_version", "4.13.2") + set("junit_jupiter_version", "5.10.0") + set("mockito_version", "5.5.0") + set("dexmaker_version", "1.2") + set("retrofit2_version", "2.9.0") + set("okhttp3_version", "4.11.0") + set("byteBuddy_version", "1.12.8") + + set("androidx_junit_version", "1.1.5") + set("androidx_rules_version", "1.5.0") + + set("rxandroidble_version", "1.12.1") + set("replayshare_version", "2.2.0") + + set("wearable_version", "2.9.0") + set("play_services_wearable_version", "18.1.0") + set("play_services_location_version", "21.0.1") + set("play_services_measurement_version", "21.3.0") + + set("kotlinx_datetime_version", "0.4.1") + set("kotlinx_serialization_version", "1.6.0") + + set("caverock_androidsvg_version", "1.4") + } + repositories { + google() + mavenCentral() + } + dependencies { + classpath("com.android.tools.build:gradle:8.1.1") + classpath("com.google.gms:google-services:4.4.0") + classpath("com.google.firebase:firebase-crashlytics-gradle:2.9.9") + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + + classpath(kotlin("gradle-plugin", version = Libs.Kotlin.kotlin)) + classpath(kotlin("allopen", version = Libs.Kotlin.kotlin)) + classpath(kotlin("serialization", version = Libs.Kotlin.kotlin)) + } +} + +plugins { + id("org.jlleitschuh.gradle.ktlint") version "11.6.0" + id("org.jetbrains.kotlin.android") version Libs.Kotlin.kotlin apply false +} + +allprojects { + repositories { + google() + mavenCentral() + maven("https://maven.google.com") + maven("https://jitpack.io") + } + tasks.withType { + kotlinOptions { + freeCompilerArgs = listOf( + "-opt-in=kotlin.RequiresOptIn", + "-Xjvm-default=all" //Support @JvmDefault + ) + jvmTarget = "11" + } + } + gradle.projectsEvaluated { + tasks.withType { + val compilerArgs = options.compilerArgs + compilerArgs.add("-Xlint:deprecation") + compilerArgs.add("-Xlint:unchecked") + } + } + + apply(plugin = "org.jlleitschuh.gradle.ktlint") + apply(plugin = "jacoco") +} + +// Setup all al reports aggregation +apply(from = "jacoco_project.gradle") + +tasks.register("clean").configure { + delete(rootProject.buildDir) +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000000..b22ed732fd --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt new file mode 100644 index 0000000000..5c4a55b760 --- /dev/null +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -0,0 +1,69 @@ +@Suppress("SpellCheckingInspection") +object Libs { + + object Kotlin { + const val kotlin = "1.9.10" + + } + object AndroidX { + const val core = "androidx.core:core-ktx:1.12.0" + } + object Dagger { + private const val dagger = "2.48" + const val androidProcessor = "com.google.dagger:dagger-android-processor:$dagger" + const val compiler = "com.google.dagger:dagger-compiler:$dagger" + } + + object Rx { + const val rxDogTag = "com.uber.rxdogtag2:rxdogtag:2.0.2" + } + const val rxjava = "3.1.7" + const val rxandroid = "3.0.2" + const val rxkotlin = "3.0.1" + const val room = "2.5.2" + const val lifecycle = "2.6.2" + const val coroutines = "1.7.3" + const val activity = "1.7.2" + const val fragmentktx = "1.6.1" + const val ormLite = "4.46" + const val gson = "2.10.1" + const val nav = "2.7.3" + const val appcompat = "1.6.1" + const val material = "1.9.0" + const val gridlayout = "1.0.0" + const val constraintlayout = "2.1.4" + const val preferencektx = "1.2.1" + const val commonslang3 = "3.13.0" + const val commonscodec = "1.16.0" + const val guava = "32.1.2-jre" + const val jodatime = "2.12.5" + const val work = "2.8.1" + const val tink = "1.10.0" + const val json = "20230618" + const val joda = "2.12.5" + const val swipe = "1.1.0" + + const val junit = "4.13.2" + const val junit_jupiter = "5.10.0" + const val mockito = "5.5.0" + const val dexmaker = "1.2" + const val retrofit2 = "2.9.0" + const val okhttp3 = "4.11.0" + const val byteBuddy = "1.12.8" + + const val androidx_junit = "1.1.5" + const val androidx_rules = "1.5.0" + + const val rxandroidble = "1.12.1" + const val replayshare = "2.2.0" + + const val wearable = "2.9.0" + const val play_services_wearable = "18.1.0" + const val play_services_location = "21.0.1" + const val play_services_measurement = "21.3.0" + + const val kotlinx_datetime = "0.4.1" + const val kotlinx_serialization = "1.6.0" + + const val caverock_androidsvg = "1.4" +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt new file mode 100644 index 0000000000..a5e777638f --- /dev/null +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -0,0 +1,7 @@ +object Versions { + + const val appVersion = "3.2.0-dev-k" + const val versionCode = 1500 + + const val ndkVersion = "21.1.6352462" +} \ No newline at end of file diff --git a/core/graphview/build.gradle b/core/graphview/build.gradle deleted file mode 100644 index cf3075074d..0000000000 --- a/core/graphview/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -plugins { - id 'com.android.library' - id 'kotlin-android' - id 'kotlin-kapt' - } - -apply from: "${project.rootDir}/core/main/android_dependencies.gradle" -apply from: "${project.rootDir}/core/main/android_module_dependencies.gradle" - -android { - - namespace 'com.jjoe64.graphview' -} - -dependencies { - api "androidx.core:core-ktx:$core_version" -} \ No newline at end of file diff --git a/core/graphview/build.gradle.kts b/core/graphview/build.gradle.kts new file mode 100644 index 0000000000..390515fab8 --- /dev/null +++ b/core/graphview/build.gradle.kts @@ -0,0 +1,17 @@ +plugins { + id("com.android.library") + id("kotlin-android") + id("kotlin-kapt") +} + +apply(from = "${project.rootDir}/core/main/android_dependencies.gradle") +apply(from = "${project.rootDir}/core/main/android_module_dependencies.gradle") + +android { + + namespace = "com.jjoe64.graphview" +} + +dependencies { + api(Libs.AndroidX.core) +} \ No newline at end of file