From 4cc5ee5a120c2572e657c121aa6ca7f84288c732 Mon Sep 17 00:00:00 2001 From: Peter Storch Date: Thu, 26 Oct 2023 17:17:10 +0200 Subject: [PATCH] Migrate build files to kotlin dsl --- app/build.gradle | 143 ----------------- app/build.gradle.kts | 144 ++++++++++++++++++ .../fdroidbuildstatus/AppInfoFragment.kt | 4 - .../fdroidbuildstatus/model/AppBuild.kt | 5 +- build.gradle | 7 - build.gradle.kts | 7 + settings.gradle => settings.gradle.kts | 9 +- 7 files changed, 159 insertions(+), 160 deletions(-) delete mode 100644 app/build.gradle create mode 100644 app/build.gradle.kts delete mode 100644 build.gradle create mode 100644 build.gradle.kts rename settings.gradle => settings.gradle.kts (73%) diff --git a/app/build.gradle b/app/build.gradle deleted file mode 100644 index c5ee429..0000000 --- a/app/build.gradle +++ /dev/null @@ -1,143 +0,0 @@ -plugins { - id 'com.android.application' - id 'de.mannodermaus.android-junit5' - id 'org.jetbrains.kotlin.android' -} - -def getVersionCode = { -> - try { - def stdout = new ByteArrayOutputStream() - exec { - commandLine 'git', 'rev-list', 'HEAD', '--count' - standardOutput = stdout - } - return Integer.valueOf(stdout.toString().trim()) - } catch (ignored) { - return null - } -} - -android { - - defaultConfig { - testInstrumentationRunnerArguments runnerBuilder: 'de.mannodermaus.junit5.AndroidJUnit5Builder' - applicationId "de.storchp.fdroidbuildstatus" - compileSdk 34 - minSdk 24 - targetSdk 34 - versionCode 54 - versionName "5.0.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - - signingConfigs { - nightly { - if (System.getProperty("nightly_store_file") != null) { - storeFile file(System.getProperty("nightly_store_file")) - storePassword System.getProperty("nightly_store_password") - keyAlias System.getProperty("nightly_key_alias") - keyPassword System.getProperty("nightly_key_password") - } - } - } - - buildTypes { - debug { - applicationIdSuffix ".debug" - versionNameSuffix "-debug" - } - nightly { - signingConfig signingConfigs.nightly - applicationIdSuffix ".nightly" - } - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_17 - targetCompatibility JavaVersion.VERSION_17 - } - - kotlinOptions { - jvmTarget = 17 - } - - buildFeatures { - viewBinding true - } - namespace 'de.storchp.fdroidbuildstatus' - lint { - disable 'MissingTranslation' - } - - sourceSets { - main.java.srcDirs += 'src/main/kotlin' - } - - applicationVariants.configureEach { variant -> - variant.resValue "string", "applicationId", variant.applicationId - - if (variant.buildType.name == 'nightly') { - variant.outputs.configureEach { - setVersionCodeOverride(getVersionCode()) - setVersionNameOverride(versionName + "-" + versionCode) - outputFileName = "${applicationId}_${variant.versionCode}.apk" - } - } - } - -} - -ext { - retrofitVersion = '2.9.0' - lifecycle_version = "2.6.2" - junitVersion = '5.10.0' - assertJVersion = '3.24.2' -} - -dependencies { - - coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.0.3" - - implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" - implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion" - implementation "com.squareup.retrofit2:converter-jackson:$retrofitVersion" - implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0' - - // Fix #145: https://github.com/FasterXML/jackson-databind/issues/3412 - // jackson 2.13 is the last supporting Android SDK 21+, 2.14 requires 26+ - // https://github.com/FasterXML/jackson/wiki/Jackson-Releases - //noinspection GradleDependency - implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.4' - implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4' - - implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" - implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0' - implementation 'androidx.appcompat:appcompat:1.6.1' - implementation 'androidx.preference:preference-ktx:1.2.1' - implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' - implementation 'com.google.android.material:material:1.10.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - implementation 'com.google.code.gson:gson:2.10.1' - - testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" - testImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion" - testImplementation "org.assertj:assertj-core:$assertJVersion" - testImplementation 'org.mockito:mockito-core:5.6.0' - testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0' - testImplementation 'org.awaitility:awaitility:4.2.0' - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" - - androidTestImplementation 'androidx.test.ext:junit:1.1.5' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' - androidTestImplementation 'androidx.test:runner:1.5.2' - androidTestImplementation 'de.mannodermaus.junit5:android-test-core:1.3.0' - androidTestImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" - androidTestImplementation "org.junit.jupiter:junit-jupiter-params:$junitVersion" - androidTestImplementation "org.assertj:assertj-core:$assertJVersion" - androidTestRuntimeOnly 'de.mannodermaus.junit5:android-test-runner:1.3.0' -} diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..6e83f02 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,144 @@ +import java.io.ByteArrayOutputStream + +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") + id("de.mannodermaus.android-junit5") +} + +fun getGitVersionCode(): Int { + return try { + val stdout = ByteArrayOutputStream() + exec { + commandLine("git", "rev-list", "HEAD", "--count") + standardOutput = stdout + } + Integer.valueOf(stdout.toString().trim()) + } catch (ignored: Exception) { + 0 + } +} + +android { + + defaultConfig { + testInstrumentationRunnerArguments += + mutableMapOf("runnerBuilder" to "de.mannodermaus.junit5.AndroidJUnit5Builder") + applicationId = "de.storchp.fdroidbuildstatus" + compileSdk = 34 + minSdk = 24 + targetSdk = 34 + versionCode = 54 + versionName = "5.0.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + + signingConfigs { + register("nightly") { + if (System.getProperty("nightly_store_file") != null) { + storeFile = file(System.getProperty("nightly_store_file")) + storePassword = System.getProperty("nightly_store_password") + keyAlias = System.getProperty("nightly_key_alias") + keyPassword = System.getProperty("nightly_key_password") + } + } + } + + buildTypes { + getByName("debug") { + applicationIdSuffix = ".debug" + versionNameSuffix = "-debug" + } + register("nightly") { + signingConfig = signingConfigs.getByName("nightly") + applicationIdSuffix = ".nightly" + } + getByName("release") { + isMinifyEnabled = true + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + + kotlinOptions { + jvmTarget = "17" + } + + buildFeatures { + viewBinding = true + } + + lint { + disable.add("MissingTranslation") + } + + namespace = "de.storchp.fdroidbuildstatus" + + applicationVariants.all { + resValue("string", "applicationId", applicationId) + + if (name == "nightly") { + outputs.forEach { output -> + output as com.android.build.gradle.internal.api.ApkVariantOutputImpl + output.versionCodeOverride = getGitVersionCode() + output.versionNameOverride = "${applicationId}_${output.versionCode}" + output.outputFileName = "${applicationId}_${versionCode}.apk" + } + } + outputs.forEach { output -> + output as com.android.build.gradle.internal.api.ApkVariantOutputImpl + output.outputFileName = "${applicationId}_${output.versionCode}.apk" + } + } + +} + +dependencies { + coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3") + + implementation("com.squareup.retrofit2:retrofit:2.9.0") + implementation("com.squareup.retrofit2:converter-gson:2.9.0") + implementation("com.squareup.retrofit2:converter-jackson:2.9.0") + implementation("com.squareup.okhttp3:logging-interceptor:4.12.0") + + // Fix #145: https://github.com/FasterXML/jackson-databind/issues/3412 + // jackson 2.13 is the last supporting Android SDK 21+, 2.14 requires 26+ + // https://github.com/FasterXML/jackson/wiki/Jackson-Releases + //noinspection GradleDependency + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.4") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4") + + implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2") + implementation("androidx.localbroadcastmanager:localbroadcastmanager:1.1.0") + implementation("androidx.appcompat:appcompat:1.6.1") + implementation("androidx.preference:preference-ktx:1.2.1") + implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0") + implementation("com.google.android.material:material:1.10.0") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + implementation("com.google.code.gson:gson:2.10.1") + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0") + testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.0") + testImplementation("org.assertj:assertj-core:3.24.2") + testImplementation("org.mockito:mockito-core:5.6.0") + testImplementation("com.squareup.okhttp3:mockwebserver:4.12.0") + testImplementation("org.awaitility:awaitility:4.2.0") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0") + + androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") + androidTestImplementation("androidx.test:runner:1.5.2") + androidTestImplementation("de.mannodermaus.junit5:android-test-core:1.3.0") + androidTestImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0") + androidTestImplementation("org.junit.jupiter:junit-jupiter-params:5.10.0") + androidTestImplementation("org.assertj:assertj-core:3.24.2") + androidTestRuntimeOnly("de.mannodermaus.junit5:android-test-runner:1.3.0") +} diff --git a/app/src/main/kotlin/de/storchp/fdroidbuildstatus/AppInfoFragment.kt b/app/src/main/kotlin/de/storchp/fdroidbuildstatus/AppInfoFragment.kt index 8e8ccb7..03bdeef 100644 --- a/app/src/main/kotlin/de/storchp/fdroidbuildstatus/AppInfoFragment.kt +++ b/app/src/main/kotlin/de/storchp/fdroidbuildstatus/AppInfoFragment.kt @@ -35,10 +35,6 @@ class AppInfoFragment : DialogFragment() { return builder.create() } - override fun onDestroyView() { - super.onDestroyView() - } - private fun getLastUpdate(buildRuns: Map, runType: BuildCycle): String { return buildRuns[runType]?.let { it.lastUpdated.time.let { it1 -> FormatUtils.formatShortDateTime(it1) } diff --git a/app/src/main/kotlin/de/storchp/fdroidbuildstatus/model/AppBuild.kt b/app/src/main/kotlin/de/storchp/fdroidbuildstatus/model/AppBuild.kt index 6bd3db7..000b2ba 100644 --- a/app/src/main/kotlin/de/storchp/fdroidbuildstatus/model/AppBuild.kt +++ b/app/src/main/kotlin/de/storchp/fdroidbuildstatus/model/AppBuild.kt @@ -21,10 +21,7 @@ data class AppBuild @JvmOverloads constructor( val buildCycleCompare = buildCycle.compareTo(other.buildCycle) return if (buildCycleCompare != 0) { buildCycleCompare - } else -Integer.compare( - versionCode.toInt(), - other.versionCode.toInt() - ) + } else -versionCode.toInt().compareTo(other.versionCode.toInt()) } override fun equals(other: Any?): Boolean { diff --git a/build.gradle b/build.gradle deleted file mode 100644 index b71f441..0000000 --- a/build.gradle +++ /dev/null @@ -1,7 +0,0 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. -plugins { - id 'com.android.application' version '8.1.2' apply false - id 'com.android.library' version '8.1.2' apply false - id 'de.mannodermaus.android-junit5' version '1.8.2.1' apply false - id 'org.jetbrains.kotlin.android' version '1.8.10' apply false -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..e62c345 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,7 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + id("com.android.application") version "8.1.2" apply false + id("com.android.library") version "8.1.2" apply false + id("de.mannodermaus.android-junit5") version "1.8.2.1" apply false + id("org.jetbrains.kotlin.android") version "1.8.10" apply false +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle.kts similarity index 73% rename from settings.gradle rename to settings.gradle.kts index 8ec5443..196486b 100644 --- a/settings.gradle +++ b/settings.gradle.kts @@ -6,14 +6,19 @@ pluginManagement { mavenCentral() } } + +@Suppress("UnstableApiUsage") dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() - maven { url 'https://jitpack.io' } + maven { + setUrl("https://jitpack.io") + } } } -include ':app' + +include(":app") rootProject.name = "F-Droid Build Status" \ No newline at end of file