Extract application build setup to plugin
This commit is contained in:
@@ -9,9 +9,8 @@ import java.io.FileInputStream
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("kotlin-android")
|
id("gq.kirmanak.mealient.application")
|
||||||
id("kotlin-kapt")
|
id("kotlin-kapt")
|
||||||
id("com.android.application")
|
|
||||||
id("androidx.navigation.safeargs.kotlin")
|
id("androidx.navigation.safeargs.kotlin")
|
||||||
id("dagger.hilt.android.plugin")
|
id("dagger.hilt.android.plugin")
|
||||||
id("org.jetbrains.kotlin.plugin.serialization")
|
id("org.jetbrains.kotlin.plugin.serialization")
|
||||||
@@ -23,12 +22,8 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdk = libs.versions.compileSdk.get().toInt()
|
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "gq.kirmanak.mealient"
|
applicationId = "gq.kirmanak.mealient"
|
||||||
minSdk = libs.versions.minSdk.get().toInt()
|
|
||||||
targetSdk = libs.versions.targetSdk.get().toInt()
|
|
||||||
versionCode = 13
|
versionCode = 13
|
||||||
versionName = "0.2.4"
|
versionName = "0.2.4"
|
||||||
|
|
||||||
@@ -110,10 +105,6 @@ android {
|
|||||||
packagingOptions {
|
packagingOptions {
|
||||||
resources.excludes += "DebugProbesKt.bin"
|
resources.excludes += "DebugProbesKt.bin"
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
|
||||||
isCoreLibraryDesugaringEnabled = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<Test>().configureEach {
|
tasks.withType<Test>().configureEach {
|
||||||
@@ -130,8 +121,6 @@ tasks.withType<KotlinCompile> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
coreLibraryDesugaring(libs.android.tools.desugar)
|
|
||||||
|
|
||||||
implementation(libs.android.material.material)
|
implementation(libs.android.material.material)
|
||||||
|
|
||||||
implementation(libs.androidx.navigation.fragmentKtx)
|
implementation(libs.androidx.navigation.fragmentKtx)
|
||||||
|
|||||||
2
build-logic/convention/.gitignore
vendored
Normal file
2
build-logic/convention/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/build
|
||||||
|
|
||||||
19
build-logic/convention/build.gradle.kts
Normal file
19
build-logic/convention/build.gradle.kts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
plugins {
|
||||||
|
`kotlin-dsl`
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "gq.kirmanak.mealient.buildlogic"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(libs.jetbrains.kotlinPlugin)
|
||||||
|
implementation(libs.android.gradlePlugin)
|
||||||
|
}
|
||||||
|
|
||||||
|
gradlePlugin {
|
||||||
|
plugins {
|
||||||
|
register("androidApplication") {
|
||||||
|
id = "gq.kirmanak.mealient.application"
|
||||||
|
implementationClass = "AndroidApplicationConventionPlugin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
|
||||||
|
import gq.kirmanak.mealient.Versions
|
||||||
|
import gq.kirmanak.mealient.configureKotlinAndroid
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.kotlin.dsl.configure
|
||||||
|
|
||||||
|
class AndroidApplicationConventionPlugin : Plugin<Project> {
|
||||||
|
|
||||||
|
override fun apply(target: Project) {
|
||||||
|
with(target) {
|
||||||
|
with(pluginManager) {
|
||||||
|
apply("com.android.application")
|
||||||
|
apply("org.jetbrains.kotlin.android")
|
||||||
|
}
|
||||||
|
|
||||||
|
extensions.configure<BaseAppModuleExtension> {
|
||||||
|
configureKotlinAndroid(this)
|
||||||
|
defaultConfig.targetSdk = Versions.TARGET_SDK_VERSION
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
@file:Suppress("UnstableApiUsage")
|
||||||
|
|
||||||
|
package gq.kirmanak.mealient
|
||||||
|
|
||||||
|
import com.android.build.api.dsl.CommonExtension
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.plugins.ExtensionAware
|
||||||
|
import org.gradle.kotlin.dsl.dependencies
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
|
||||||
|
|
||||||
|
internal fun Project.configureKotlinAndroid(
|
||||||
|
commonExtension: CommonExtension<*, *, *, *>,
|
||||||
|
) {
|
||||||
|
commonExtension.apply {
|
||||||
|
compileSdk = Versions.COMPILE_SDK_VERSION
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdk = Versions.MIN_SDK_VERSION
|
||||||
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
isCoreLibraryDesugaringEnabled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinOptions {
|
||||||
|
freeCompilerArgs = freeCompilerArgs + listOf("-opt-in=kotlin.RequiresOptIn")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
add("coreLibraryDesugaring", libs.findLibrary("android-tools-desugar").get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun CommonExtension<*, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
|
||||||
|
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package gq.kirmanak.mealient
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.artifacts.VersionCatalog
|
||||||
|
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||||
|
import org.gradle.kotlin.dsl.getByType
|
||||||
|
|
||||||
|
object Versions {
|
||||||
|
const val MIN_SDK_VERSION = 23
|
||||||
|
const val TARGET_SDK_VERSION = 32
|
||||||
|
const val COMPILE_SDK_VERSION = 32
|
||||||
|
}
|
||||||
|
|
||||||
|
val Project.libs: VersionCatalog
|
||||||
|
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")
|
||||||
4
build-logic/gradle.properties
Normal file
4
build-logic/gradle.properties
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# Gradle properties are not passed to included builds https://github.com/gradle/gradle/issues/2534
|
||||||
|
org.gradle.parallel=true
|
||||||
|
org.gradle.caching=true
|
||||||
|
org.gradle.configureondemand=true
|
||||||
15
build-logic/settings.gradle.kts
Normal file
15
build-logic/settings.gradle.kts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
@file:Suppress("UnstableApiUsage")
|
||||||
|
|
||||||
|
dependencyResolutionManagement {
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
versionCatalogs {
|
||||||
|
create("libs") {
|
||||||
|
from(files("../gradle/libs.versions.toml"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
include(":convention")
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
[versions]
|
[versions]
|
||||||
compileSdk = "32"
|
|
||||||
minSdk = "23"
|
|
||||||
targetSdk = "32"
|
|
||||||
|
|
||||||
# https://maven.google.com/web/index.html?q=com.android.tools.build#com.android.tools.build:gradle
|
# https://maven.google.com/web/index.html?q=com.android.tools.build#com.android.tools.build:gradle
|
||||||
androidGradlePlugin = "7.2.1"
|
androidGradlePlugin = "7.2.1"
|
||||||
# https://developers.google.com/android/guides/google-services-plugin
|
# https://developers.google.com/android/guides/google-services-plugin
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
@file:Suppress("UnstableApiUsage")
|
@file:Suppress("UnstableApiUsage")
|
||||||
|
|
||||||
|
pluginManagement {
|
||||||
|
includeBuild("build-logic")
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencyResolutionManagement {
|
dependencyResolutionManagement {
|
||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
Reference in New Issue
Block a user