mirror of
https://github.com/d4rken-org/capod.git
synced 2026-09-16 03:06:11 -04:00
Use Kotlin for Gradle DSL
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
import org.gradle.api.artifacts.Dependency
|
||||
import org.gradle.api.artifacts.dsl.DependencyHandler
|
||||
import org.gradle.kotlin.dsl.DependencyHandlerScope
|
||||
|
||||
private fun DependencyHandler.implementation(dependencyNotation: Any): Dependency? =
|
||||
add("implementation", dependencyNotation)
|
||||
|
||||
private fun DependencyHandler.testImplementation(dependencyNotation: Any): Dependency? =
|
||||
add("testImplementation", dependencyNotation)
|
||||
|
||||
private fun DependencyHandler.kapt(dependencyNotation: Any): Dependency? =
|
||||
add("kapt", dependencyNotation)
|
||||
|
||||
private fun DependencyHandler.kaptTest(dependencyNotation: Any): Dependency? =
|
||||
add("kaptTest", dependencyNotation)
|
||||
|
||||
private fun DependencyHandler.androidTestImplementation(dependencyNotation: Any): Dependency? =
|
||||
add("androidTestImplementation", dependencyNotation)
|
||||
|
||||
private fun DependencyHandler.kaptAndroidTest(dependencyNotation: Any): Dependency? =
|
||||
add("kaptAndroidTest", dependencyNotation)
|
||||
|
||||
private fun DependencyHandler.`testRuntimeOnly`(dependencyNotation: Any): Dependency? =
|
||||
add("testRuntimeOnly", dependencyNotation)
|
||||
|
||||
private fun DependencyHandler.`debugImplementation`(dependencyNotation: Any): Dependency? =
|
||||
add("debugImplementation", dependencyNotation)
|
||||
|
||||
fun DependencyHandlerScope.addBaseKotlin() {
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib:${Versions.Kotlin.core}")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.Kotlin.coroutines}")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.Kotlin.coroutines}")
|
||||
|
||||
testImplementation("org.jetbrains.kotlin:kotlin-reflect:${Versions.Kotlin.core}")
|
||||
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.Kotlin.coroutines}")
|
||||
|
||||
androidTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:${Versions.Kotlin.coroutines}")
|
||||
// {
|
||||
// // conflicts with mockito due to direct inclusion of byte buddy
|
||||
// exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-debug")
|
||||
// }
|
||||
}
|
||||
|
||||
fun DependencyHandlerScope.addDagger() {
|
||||
implementation("com.google.dagger:dagger:${Versions.Dagger.core}")
|
||||
implementation("com.google.dagger:dagger-android:${Versions.Dagger.core}")
|
||||
implementation("androidx.hilt:hilt-common:1.0.0")
|
||||
|
||||
kapt("com.google.dagger:dagger-compiler:${Versions.Dagger.core}")
|
||||
kapt("com.google.dagger:dagger-android-processor:${Versions.Dagger.core}")
|
||||
|
||||
implementation("com.google.dagger:hilt-android:${Versions.Dagger.core}")
|
||||
kapt("com.google.dagger:hilt-android-compiler:${Versions.Dagger.core}")
|
||||
|
||||
testImplementation("com.google.dagger:hilt-android-testing:${Versions.Dagger.core}")
|
||||
kaptTest("com.google.dagger:hilt-android-compiler:${Versions.Dagger.core}")
|
||||
|
||||
androidTestImplementation("com.google.dagger:hilt-android-testing:${Versions.Dagger.core}")
|
||||
kaptAndroidTest("com.google.dagger:hilt-android-compiler:${Versions.Dagger.core}")
|
||||
}
|
||||
|
||||
fun DependencyHandlerScope.addMoshi() {
|
||||
implementation("com.squareup.moshi:moshi:${Versions.Moshi.core}")
|
||||
implementation("com.squareup.moshi:moshi-adapters:${Versions.Moshi.core}")
|
||||
kapt("com.squareup.moshi:moshi-kotlin-codegen:${Versions.Moshi.core}")
|
||||
}
|
||||
|
||||
fun DependencyHandlerScope.addOkio() {
|
||||
implementation("com.squareup.okio:okio:3.1.0")
|
||||
}
|
||||
|
||||
fun DependencyHandlerScope.addNavigation() {
|
||||
implementation("androidx.navigation:navigation-fragment-ktx:${Versions.AndroidX.Navigation.core}")
|
||||
implementation("androidx.navigation:navigation-ui-ktx:${Versions.AndroidX.Navigation.core}")
|
||||
androidTestImplementation("androidx.navigation:navigation-testing:${Versions.AndroidX.Navigation.core}")
|
||||
}
|
||||
|
||||
fun DependencyHandlerScope.addBaseWorkManager() {
|
||||
implementation("androidx.work:work-runtime:${Versions.AndroidX.WorkManager.core}")
|
||||
testImplementation("androidx.work:work-testing:${Versions.AndroidX.WorkManager.core}")
|
||||
implementation("androidx.work:work-runtime-ktx:${Versions.AndroidX.WorkManager.core}")
|
||||
implementation("androidx.hilt:hilt-work:1.0.0")
|
||||
}
|
||||
|
||||
fun DependencyHandlerScope.addBaseAndroid() {
|
||||
implementation("androidx.core:core-ktx:1.8.0")
|
||||
implementation("androidx.annotation:annotation:1.4.0")
|
||||
implementation("androidx.collection:collection-ktx:1.2.0")
|
||||
implementation("androidx.preference:preference-ktx:1.2.0")
|
||||
}
|
||||
|
||||
fun DependencyHandlerScope.addBaseAndroidUi() {
|
||||
implementation("androidx.appcompat:appcompat:1.6.0-alpha04")
|
||||
implementation("androidx.constraintlayout:constraintlayout:2.1.3")
|
||||
implementation("androidx.fragment:fragment-ktx:1.4.1")
|
||||
|
||||
implementation("androidx.activity:activity-ktx:1.5.0")
|
||||
implementation("androidx.fragment:fragment-ktx:1.5.0")
|
||||
|
||||
val lifecycleVers = "2.5.0"
|
||||
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
|
||||
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVers")
|
||||
implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycleVers")
|
||||
implementation("androidx.lifecycle:lifecycle-common-java8:$lifecycleVers")
|
||||
implementation("androidx.lifecycle:lifecycle-process:$lifecycleVers")
|
||||
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVers")
|
||||
}
|
||||
|
||||
fun DependencyHandlerScope.addTesting(junit: Boolean = true, instrumentation: Boolean = true) {
|
||||
testImplementation("junit:junit:${Versions.Junit.legacy}")
|
||||
|
||||
testImplementation("org.junit.vintage:junit-vintage-engine:${Versions.Junit.jupiter}")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${Versions.Junit.jupiter}")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api:${Versions.Junit.jupiter}")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-params:${Versions.Junit.jupiter}")
|
||||
|
||||
testImplementation("androidx.test:core-ktx:${Versions.AndroidX.Testing.coreKtx}")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.3")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
|
||||
|
||||
testImplementation("io.mockk:mockk:${Versions.Mockk.core}")
|
||||
androidTestImplementation("io.mockk:mockk-android:${Versions.Mockk.android}")
|
||||
|
||||
testImplementation("io.kotest:kotest-runner-junit5:${Versions.Kotest.core}")
|
||||
testImplementation("io.kotest:kotest-assertions-core-jvm:${Versions.Kotest.core}")
|
||||
testImplementation("io.kotest:kotest-property-jvm:${Versions.Kotest.core}")
|
||||
androidTestImplementation("io.kotest:kotest-assertions-core-jvm:${Versions.Kotest.core}")
|
||||
androidTestImplementation("io.kotest:kotest-property-jvm:${Versions.Kotest.core}")
|
||||
|
||||
debugImplementation("androidx.fragment:fragment-testing:1.4.1")
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import com.android.build.gradle.LibraryExtension
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.JavaVersion
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
|
||||
object ProjectConfig {
|
||||
const val packageName = "eu.darken.capod"
|
||||
|
||||
const val minSdk = 26
|
||||
const val compileSdk = 33
|
||||
const val targetSdk = 33
|
||||
|
||||
object Version {
|
||||
const val major = 2
|
||||
const val minor = 0
|
||||
const val patch = 0
|
||||
const val build = 0
|
||||
|
||||
const val name = "${major}.${minor}.${patch}-rc${build}"
|
||||
const val code = major * 1000000 + minor * 10000 + patch * 100 + build
|
||||
}
|
||||
}
|
||||
|
||||
fun lastCommitHash(): String = Runtime.getRuntime().exec("git rev-parse --short HEAD").let { process ->
|
||||
process.waitFor()
|
||||
val output = process.inputStream.use { input ->
|
||||
input.bufferedReader().use {
|
||||
it.readText()
|
||||
}
|
||||
}
|
||||
process.destroy()
|
||||
output.trim()
|
||||
}
|
||||
|
||||
fun buildTime(): Instant = Instant.now()
|
||||
|
||||
/**
|
||||
* Configures the [kotlinOptions][org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions] extension.
|
||||
*/
|
||||
private fun LibraryExtension.kotlinOptions(configure: Action<org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions>): Unit =
|
||||
(this as org.gradle.api.plugins.ExtensionAware).extensions.configure("kotlinOptions", configure)
|
||||
|
||||
fun LibraryExtension.setupLibraryDefaults() {
|
||||
compileSdk = ProjectConfig.compileSdk
|
||||
|
||||
defaultConfig {
|
||||
minSdk = ProjectConfig.minSdk
|
||||
targetSdk = ProjectConfig.targetSdk
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles("consumer-rules.pro")
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
isCoreLibraryDesugaringEnabled = true
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs = freeCompilerArgs + listOf(
|
||||
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
|
||||
"-Xopt-in=kotlinx.coroutines.FlowPreview",
|
||||
"-Xopt-in=kotlin.time.ExperimentalTime",
|
||||
"-Xopt-in=kotlin.RequiresOptIn"
|
||||
)
|
||||
}
|
||||
|
||||
packagingOptions {
|
||||
resources.excludes += "DebugProbesKt.bin"
|
||||
}
|
||||
}
|
||||
|
||||
fun com.android.build.api.dsl.SigningConfig.setupCredentials(
|
||||
signingPropsPath: File? = null
|
||||
) {
|
||||
|
||||
val keyStoreFromEnv = System.getenv("STORE_PATH")?.let { File(it) }
|
||||
|
||||
if (keyStoreFromEnv?.exists() == true) {
|
||||
println("Using signing data from environment variables.")
|
||||
storeFile = keyStoreFromEnv
|
||||
storePassword = System.getenv("STORE_PASSWORD")
|
||||
keyAlias = System.getenv("KEY_ALIAS")
|
||||
keyPassword = System.getenv("KEY_PASSWORD")
|
||||
} else {
|
||||
println("Using signing data from properties file.")
|
||||
val props = Properties().apply {
|
||||
signingPropsPath?.takeIf { it.canRead() }?.let { load(FileInputStream(it)) }
|
||||
}
|
||||
|
||||
val keyStorePath = props.getProperty("release.storePath")?.let { File(it) }
|
||||
|
||||
if (keyStorePath?.exists() == true) {
|
||||
storeFile = keyStorePath
|
||||
storePassword = props.getProperty("release.storePassword")
|
||||
keyAlias = props.getProperty("release.keyAlias")
|
||||
keyPassword = props.getProperty("release.keyPassword")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getBugSnagApiKey(
|
||||
propertiesPath: File?
|
||||
): String? {
|
||||
val bugsnagProps = Properties().apply {
|
||||
propertiesPath?.takeIf { it.canRead() }?.let { load(FileInputStream(it)) }
|
||||
}
|
||||
|
||||
return System.getenv("BUGSNAG_API_KEY") ?: bugsnagProps.getProperty("bugsnag.apikey")
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
object Versions {
|
||||
object Gradle {
|
||||
const val buildTools = "7.1.2"
|
||||
}
|
||||
|
||||
object Kotlin {
|
||||
const val core = "1.7.0"
|
||||
const val coroutines = "1.6.2"
|
||||
}
|
||||
|
||||
object Dokka {
|
||||
const val core = "1.6.21"
|
||||
}
|
||||
|
||||
object Dagger {
|
||||
const val core = "2.42"
|
||||
}
|
||||
|
||||
object Moshi {
|
||||
const val core = "1.13.0"
|
||||
}
|
||||
|
||||
object AndroidX {
|
||||
const val core = ""
|
||||
|
||||
object Navigation {
|
||||
const val core = "2.5.0"
|
||||
}
|
||||
|
||||
object Testing {
|
||||
const val coreKtx = "1.4.0"
|
||||
}
|
||||
|
||||
object WorkManager {
|
||||
const val core = "2.7.1"
|
||||
}
|
||||
}
|
||||
|
||||
object Junit {
|
||||
const val legacy = "4.13.2"
|
||||
const val jupiter = "5.7.1"
|
||||
}
|
||||
|
||||
object Mockk {
|
||||
const val core = "1.12.4"
|
||||
const val android = "1.12.4"
|
||||
}
|
||||
|
||||
object Kotest {
|
||||
const val core = "4.6.4"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user