v0.6.4
This commit is contained in:
3
build-logic/gradle.properties
Normal file
3
build-logic/gradle.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
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 @@
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
versionCatalogs {
|
||||
create("libs") {
|
||||
from(files("../gradle/libs.versions.toml"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "build-logic"
|
||||
include(":structure")
|
||||
62
build-logic/structure/build.gradle.kts
Normal file
62
build-logic/structure/build.gradle.kts
Normal file
@@ -0,0 +1,62 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
group = "buildlogic"
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget = JvmTarget.JVM_17
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.android.gradlePlugin)
|
||||
compileOnly(libs.kotlin.gradlePlugin)
|
||||
compileOnly(libs.kotlin.ktlint)
|
||||
compileOnly(libs.ksp.gradlePlugin)
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
register("lintPlugin") {
|
||||
id = "looker.lint"
|
||||
implementationClass = "AndroidLintPlugin"
|
||||
}
|
||||
register("serializationPlugin") {
|
||||
id = "looker.serialization"
|
||||
implementationClass = "AndroidSerializationPlugin"
|
||||
}
|
||||
register("hiltPlugin") {
|
||||
id = "looker.hilt"
|
||||
implementationClass = "AndroidHiltPlugin"
|
||||
}
|
||||
register("hiltWorkPlugin") {
|
||||
id = "looker.hilt.work"
|
||||
implementationClass = "AndroidHiltWorkerPlugin"
|
||||
}
|
||||
register("roomPlugin") {
|
||||
id = "looker.room"
|
||||
implementationClass = "AndroidRoomPlugin"
|
||||
}
|
||||
register("androidApplicationPlugin") {
|
||||
id = "looker.android.application"
|
||||
implementationClass = "AndroidApplicationPlugin"
|
||||
}
|
||||
register("androidLibraryPlugin") {
|
||||
id = "looker.android.library"
|
||||
implementationClass = "AndroidLibraryPlugin"
|
||||
}
|
||||
register("jvmLibraryPlugin") {
|
||||
id = "looker.jvm.library"
|
||||
implementationClass = "JvmLibraryPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import com.android.build.api.dsl.ApplicationExtension
|
||||
import com.looker.droidify.configureKotlinAndroid
|
||||
import com.looker.droidify.kotlin2
|
||||
import com.looker.droidify.libs
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
|
||||
class AndroidApplicationPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
with(pluginManager) {
|
||||
apply("com.android.application")
|
||||
apply("org.jetbrains.kotlin.android")
|
||||
}
|
||||
|
||||
extensions.configure<ApplicationExtension> {
|
||||
configureKotlinAndroid(this)
|
||||
buildToolsVersion = DefaultConfig.buildTools
|
||||
defaultConfig {
|
||||
targetSdk = DefaultConfig.compileSdk
|
||||
applicationId = DefaultConfig.appId
|
||||
versionCode = DefaultConfig.versionCode
|
||||
versionName = DefaultConfig.versionName
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
add("implementation", kotlin2("stdlib", libs))
|
||||
add("implementation", kotlin2("reflect", libs))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
build-logic/structure/src/main/kotlin/AndroidHiltPlugin.kt
Normal file
26
build-logic/structure/src/main/kotlin/AndroidHiltPlugin.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
import com.android.build.gradle.api.AndroidBasePlugin
|
||||
import com.looker.droidify.getLibrary
|
||||
import com.looker.droidify.libs
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
|
||||
class AndroidHiltPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
pluginManager.apply("com.google.devtools.ksp")
|
||||
dependencies {
|
||||
add("ksp", libs.getLibrary("hilt.compiler"))
|
||||
add("implementation", libs.getLibrary("hilt.core"))
|
||||
}
|
||||
|
||||
/** Add support for Android modules, based on [AndroidBasePlugin] */
|
||||
pluginManager.withPlugin("com.android.base") {
|
||||
pluginManager.apply("dagger.hilt.android.plugin")
|
||||
dependencies {
|
||||
add("implementation", libs.getLibrary("hilt.android"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import com.looker.droidify.getLibrary
|
||||
import com.looker.droidify.libs
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
|
||||
class AndroidHiltWorkerPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
with(pluginManager) {
|
||||
apply("looker.hilt")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
add("implementation", libs.getLibrary("androidx.work.ktx"))
|
||||
add("implementation", libs.getLibrary("hilt.ext.work"))
|
||||
add("ksp", libs.getLibrary("hilt.ext.compiler"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import com.android.build.api.variant.LibraryAndroidComponentsExtension
|
||||
import com.android.build.gradle.LibraryExtension
|
||||
import com.looker.droidify.configureKotlinAndroid
|
||||
import com.looker.droidify.kotlin2
|
||||
import com.looker.droidify.libs
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
|
||||
class AndroidLibraryPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
with(pluginManager) {
|
||||
apply("com.android.library")
|
||||
apply("org.jetbrains.kotlin.android")
|
||||
}
|
||||
|
||||
extensions.configure<LibraryExtension> {
|
||||
configureKotlinAndroid(this)
|
||||
defaultConfig.targetSdk = DefaultConfig.compileSdk
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"${rootDir.path}/app/proguard.pro"
|
||||
)
|
||||
}
|
||||
create("alpha") {
|
||||
initWith(getByName("debug"))
|
||||
isMinifyEnabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
extensions.configure<LibraryAndroidComponentsExtension> {
|
||||
beforeVariants {
|
||||
it.enableAndroidTest = it.enableAndroidTest
|
||||
&& project.projectDir.resolve("src/androidTest").exists()
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
add("implementation", kotlin2("stdlib", libs))
|
||||
add("implementation", kotlin2("reflect", libs))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
build-logic/structure/src/main/kotlin/AndroidLintPlugin.kt
Normal file
27
build-logic/structure/src/main/kotlin/AndroidLintPlugin.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.jlleitschuh.gradle.ktlint.KtlintExtension
|
||||
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
|
||||
|
||||
class AndroidLintPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
with(pluginManager) {
|
||||
apply("org.jlleitschuh.gradle.ktlint")
|
||||
}
|
||||
|
||||
extensions.configure<KtlintExtension> {
|
||||
android.set(true)
|
||||
ignoreFailures.set(true)
|
||||
debug.set(true)
|
||||
reporters {
|
||||
reporter(ReporterType.HTML)
|
||||
}
|
||||
filter {
|
||||
exclude("**/generated/**")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
46
build-logic/structure/src/main/kotlin/AndroidRoomPlugin.kt
Normal file
46
build-logic/structure/src/main/kotlin/AndroidRoomPlugin.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
import com.google.devtools.ksp.gradle.KspExtension
|
||||
import com.looker.droidify.getLibrary
|
||||
import com.looker.droidify.libs
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.InputDirectory
|
||||
import org.gradle.api.tasks.PathSensitive
|
||||
import org.gradle.api.tasks.PathSensitivity
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
import org.gradle.process.CommandLineArgumentProvider
|
||||
import java.io.File
|
||||
|
||||
class AndroidRoomPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
pluginManager.apply("com.google.devtools.ksp")
|
||||
|
||||
extensions.configure<KspExtension> {
|
||||
// The schemas directory contains a schema file for each version of the Room database.
|
||||
// This is required to enable Room auto migrations.
|
||||
// See https://developer.android.com/reference/kotlin/androidx/room/AutoMigration.
|
||||
arg(RoomSchemaArgProvider(File(projectDir, "schemas")))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
add("implementation", libs.getLibrary("room.ktx"))
|
||||
add("implementation", libs.getLibrary("room.runtime"))
|
||||
add("ksp", libs.getLibrary("room.compiler"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* https://issuetracker.google.com/issues/132245929
|
||||
* [Export schemas](https://developer.android.com/training/data-storage/room/migrating-db-versions#export-schemas)
|
||||
*/
|
||||
class RoomSchemaArgProvider(
|
||||
@get:InputDirectory
|
||||
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||
val schemaDir: File,
|
||||
) : CommandLineArgumentProvider {
|
||||
override fun asArguments() = listOf("room.schemaLocation=${schemaDir.path}")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import com.looker.droidify.getLibrary
|
||||
import com.looker.droidify.libs
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
|
||||
class AndroidSerializationPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
with(pluginManager) {
|
||||
apply("org.jetbrains.kotlin.plugin.serialization")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
add("implementation", libs.getLibrary("kotlinx.serialization.json"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
build-logic/structure/src/main/kotlin/DefaultConfig.kt
Normal file
10
build-logic/structure/src/main/kotlin/DefaultConfig.kt
Normal file
@@ -0,0 +1,10 @@
|
||||
object DefaultConfig {
|
||||
|
||||
|
||||
|
||||
|
||||
// Update [release_build.yml] along with this
|
||||
|
||||
|
||||
|
||||
|
||||
14
build-logic/structure/src/main/kotlin/JvmLibraryPlugin.kt
Normal file
14
build-logic/structure/src/main/kotlin/JvmLibraryPlugin.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
import com.looker.droidify.configureKotlinJvm
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
class JvmLibraryPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
with(pluginManager) {
|
||||
apply("org.jetbrains.kotlin.jvm")
|
||||
}
|
||||
configureKotlinJvm()
|
||||
}
|
||||
}
|
||||
}
|
||||
21
build-logic/structure/src/main/kotlin/Modules.kt
Normal file
21
build-logic/structure/src/main/kotlin/Modules.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
import org.gradle.kotlin.dsl.DependencyHandlerScope
|
||||
import org.gradle.kotlin.dsl.project
|
||||
|
||||
object Modules {
|
||||
const val app = ":app"
|
||||
const val coreCommon = ":core:common"
|
||||
const val coreData = ":core:data"
|
||||
const val coreDatabase = ":core:database"
|
||||
const val coreDatastore = ":core:datastore"
|
||||
const val coreDI = ":core:di"
|
||||
const val coreDomain = ":core:domain"
|
||||
const val coreNetwork = ":core:network"
|
||||
const val installer = ":installer"
|
||||
const val sync = ":sync:fdroid"
|
||||
}
|
||||
|
||||
fun DependencyHandlerScope.modules(vararg module: String) {
|
||||
module.forEach {
|
||||
add("implementation", project(it))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.looker.droidify
|
||||
|
||||
import DefaultConfig
|
||||
import com.android.build.api.dsl.CommonExtension
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.JavaPluginExtension
|
||||
import org.gradle.kotlin.dsl.assign
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinBaseExtension
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
|
||||
|
||||
// Taken from NIA sample app by Google
|
||||
|
||||
/**
|
||||
* Configure base Kotlin with Android options
|
||||
*/
|
||||
internal fun Project.configureKotlinAndroid(
|
||||
commonExtension: CommonExtension<*, *, *, *, *, *>,
|
||||
) {
|
||||
commonExtension.apply {
|
||||
compileSdk = DefaultConfig.compileSdk
|
||||
|
||||
defaultConfig {
|
||||
minSdk = DefaultConfig.minSdk
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
// Up to Java 11 APIs are available through desugaring
|
||||
// https://developer.android.com/studio/write/java11-minimal-support-table
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
isCoreLibraryDesugaringEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
configureKotlin<KotlinAndroidProjectExtension>()
|
||||
|
||||
dependencies {
|
||||
add("coreLibraryDesugaring", libs.getLibrary("android.desugarJdkLibs"))
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Project.configureKotlinJvm() {
|
||||
extensions.configure<JavaPluginExtension> {
|
||||
// Up to Java 11 APIs are available through desugaring
|
||||
// https://developer.android.com/studio/write/java11-minimal-support-table
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
configureKotlin<KotlinJvmProjectExtension>()
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure base Kotlin options
|
||||
*/
|
||||
private inline fun <reified T : KotlinBaseExtension> Project.configureKotlin() = configure<T> {
|
||||
when (this) {
|
||||
is KotlinAndroidProjectExtension -> compilerOptions
|
||||
is KotlinJvmProjectExtension -> compilerOptions
|
||||
else -> TODO("Unsupported project extension $this ${T::class}")
|
||||
}.apply {
|
||||
// Use when hilt supports ksp2
|
||||
// apiVersion = KotlinVersion.KOTLIN_2_0
|
||||
jvmTarget = JvmTarget.JVM_11
|
||||
freeCompilerArgs = listOf(
|
||||
"-opt-in=kotlin.RequiresOptIn",
|
||||
// Enable experimental coroutines APIs, including Flow
|
||||
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
|
||||
"-opt-in=kotlinx.coroutines.FlowPreview",
|
||||
"-Xcontext-receivers"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.looker.droidify
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.MinimalExternalModuleDependency
|
||||
import org.gradle.api.artifacts.VersionCatalog
|
||||
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||
import org.gradle.api.artifacts.dsl.DependencyHandler
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import org.gradle.kotlin.dsl.kotlin
|
||||
|
||||
val Project.libs
|
||||
get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
|
||||
|
||||
fun VersionCatalog.getLibrary(alias: String): Provider<MinimalExternalModuleDependency> =
|
||||
findLibrary(alias).get()
|
||||
|
||||
fun DependencyHandler.kotlin2(module: String, catalog: VersionCatalog): Any =
|
||||
kotlin(module, version = catalog.findVersion("kotlin").get().strictVersion)
|
||||
Reference in New Issue
Block a user