-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added build-logic and refactor plugin
- Loading branch information
1 parent
27c4724
commit fff8516
Showing
46 changed files
with
1,738 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Convention Plugins | ||
|
||
The `build-logic` folder defines project-specific convention plugins, used to keep a single | ||
source of truth for common module configurations. | ||
|
||
This approach is heavily based on | ||
[https://developer.squareup.com/blog/herding-elephants/](https://developer.squareup.com/blog/herding-elephants/) | ||
and | ||
[https://github.com/jjohannes/idiomatic-gradle](https://github.com/jjohannes/idiomatic-gradle). | ||
|
||
By setting up convention plugins in `build-logic`, we can avoid duplicated build script setup, | ||
messy `subproject` configurations, without the pitfalls of the `buildSrc` directory. | ||
|
||
`build-logic` is an included build, as configured in the root | ||
[`settings.gradle.kts`](../settings.gradle.kts). | ||
|
||
Inside `build-logic` is a `convention` module, which defines a set of plugins that all normal | ||
modules can use to configure themselves. | ||
|
||
`build-logic` also includes a set of `Kotlin` files used to share logic between plugins themselves, | ||
which is most useful for configuring Android components (libraries vs applications) with shared | ||
code. | ||
|
||
These plugins are *additive* and *composable*, and try to only accomplish a single responsibility. | ||
Modules can then pick and choose the configurations they need. | ||
If there is one-off logic for a module without shared code, it's preferable to define that directly | ||
in the module's `build.gradle`, as opposed to creating a convention plugin with module-specific | ||
setup. | ||
|
||
Current list of convention plugins: | ||
|
||
- [`mifospay.android.application`](convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt), | ||
[`mifospay.android.library`](convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt), | ||
[`mifospay.android.test`](convention/src/main/kotlin/AndroidTestConventionPlugin.kt): | ||
Configures common Android and Kotlin options. | ||
- [`mifospay.android.application.compose`](convention/src/main/kotlin/AndroidApplicationComposeConventionPlugin.kt), | ||
[`mifospay.android.library.compose`](convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt): | ||
Configures Jetpack Compose options |
16 changes: 16 additions & 0 deletions
16
build-logic/convention/bin/main/AndroidApplicationComposeConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import com.android.build.api.dsl.ApplicationExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.mifos.configureAndroidCompose | ||
|
||
class AndroidApplicationComposeConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply("com.android.application") | ||
|
||
val extension = extensions.getByType<ApplicationExtension>() | ||
configureAndroidCompose(extension) | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
build-logic/convention/bin/main/AndroidApplicationConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import com.android.build.api.dsl.ApplicationExtension | ||
import com.android.build.api.variant.ApplicationAndroidComponentsExtension | ||
import com.android.build.gradle.BaseExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.mifos.configureBadgingTasks | ||
import org.mifos.configureKotlinAndroid | ||
import org.mifos.configurePrintApksTask | ||
|
||
class AndroidApplicationConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.android.application") | ||
apply("org.jetbrains.kotlin.android") | ||
apply("mifos.android.lint") | ||
apply("com.dropbox.dependency-guard") | ||
} | ||
|
||
extensions.configure<ApplicationExtension> { | ||
configureKotlinAndroid(this) | ||
defaultConfig.targetSdk = 34 | ||
@Suppress("UnstableApiUsage") | ||
testOptions.animationsDisabled = true | ||
} | ||
extensions.configure<ApplicationAndroidComponentsExtension> { | ||
configurePrintApksTask(this) | ||
configureBadgingTasks(extensions.getByType<BaseExtension>(), this) | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
build-logic/convention/bin/main/AndroidApplicationFirebaseConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import com.android.build.api.dsl.ApplicationExtension | ||
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.mifos.libs | ||
|
||
class AndroidApplicationFirebaseConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.google.gms.google-services") | ||
apply("com.google.firebase.firebase-perf") | ||
apply("com.google.firebase.crashlytics") | ||
} | ||
|
||
dependencies { | ||
val bom = libs.findLibrary("firebase-bom").get() | ||
add("implementation", platform(bom)) | ||
"implementation"(libs.findLibrary("firebase.analytics").get()) | ||
"implementation"(libs.findLibrary("firebase.performance").get()) | ||
"implementation"(libs.findLibrary("firebase.crashlytics").get()) | ||
"implementation"(libs.findLibrary("firebase.cloud.messaging").get()) | ||
} | ||
|
||
extensions.configure<ApplicationExtension> { | ||
buildTypes.configureEach { | ||
// Disable the Crashlytics mapping file upload. This feature should only be | ||
// enabled if a Firebase backend is available and configured in | ||
// google-services.json. | ||
configure<CrashlyticsExtension> { | ||
mappingFileUploadEnabled = false | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
build-logic/convention/bin/main/AndroidApplicationFlavorsConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import com.android.build.api.dsl.ApplicationExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.mifos.configureFlavors | ||
|
||
class AndroidApplicationFlavorsConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
extensions.configure<ApplicationExtension> { | ||
configureFlavors(this) | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
build-logic/convention/bin/main/AndroidFeatureConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import com.android.build.gradle.LibraryExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.mifos.libs | ||
|
||
class AndroidFeatureConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply { | ||
apply("mifos.android.library") | ||
apply("mifos.android.hilt") | ||
} | ||
extensions.configure<LibraryExtension> { | ||
defaultConfig { | ||
// set custom test runner | ||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
testOptions.animationsDisabled = true | ||
} | ||
|
||
dependencies { | ||
add("implementation", project(":core:data")) | ||
add("implementation", project(":core:designsystem")) | ||
add("implementation", project(":core:common")) | ||
|
||
add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get()) | ||
add("implementation", libs.findLibrary("androidx.lifecycle.runtimeCompose").get()) | ||
add("implementation", libs.findLibrary("androidx.lifecycle.viewModelCompose").get()) | ||
add("implementation", libs.findLibrary("androidx.tracing.ktx").get()) | ||
|
||
add( | ||
"androidTestImplementation", | ||
libs.findLibrary("androidx.lifecycle.runtimeTesting").get() | ||
) | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
build-logic/convention/bin/main/AndroidHiltConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.mifos.libs | ||
|
||
class AndroidHiltConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.google.devtools.ksp") | ||
apply("dagger.hilt.android.plugin") | ||
} | ||
|
||
dependencies { | ||
"implementation"(libs.findLibrary("hilt.android").get()) | ||
"ksp"(libs.findLibrary("hilt.compiler").get()) | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
build-logic/convention/bin/main/AndroidLibraryComposeConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import com.android.build.gradle.LibraryExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.mifos.configureAndroidCompose | ||
|
||
class AndroidLibraryComposeConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply("com.android.library") | ||
|
||
val extension = extensions.getByType<LibraryExtension>() | ||
configureAndroidCompose(extension) | ||
} | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
build-logic/convention/bin/main/AndroidLibraryConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import com.android.build.api.variant.LibraryAndroidComponentsExtension | ||
import com.android.build.gradle.LibraryExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.kotlin | ||
import org.mifos.configureFlavors | ||
import org.mifos.configureKotlinAndroid | ||
import org.mifos.configurePrintApksTask | ||
import org.mifos.disableUnnecessaryAndroidTests | ||
import org.mifos.libs | ||
|
||
class AndroidLibraryConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.android.library") | ||
apply("org.jetbrains.kotlin.android") | ||
apply("mifos.android.lint") | ||
} | ||
|
||
extensions.configure<LibraryExtension> { | ||
configureKotlinAndroid(this) | ||
defaultConfig.targetSdk = 34 | ||
testOptions.animationsDisabled = true | ||
configureFlavors(this) | ||
// The resource prefix is derived from the module name, | ||
// so resources inside ":core:module1" must be prefixed with "core_module1_" | ||
resourcePrefix = | ||
path.split("""\W""".toRegex()).drop(1).distinct().joinToString(separator = "_") | ||
.lowercase() + "_" | ||
} | ||
extensions.configure<LibraryAndroidComponentsExtension> { | ||
configurePrintApksTask(this) | ||
disableUnnecessaryAndroidTests(target) | ||
} | ||
dependencies { | ||
add("testImplementation", kotlin("test")) | ||
add("implementation", libs.findLibrary("androidx.tracing.ktx").get()) | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
build-logic/convention/bin/main/AndroidLintConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import com.android.build.api.dsl.ApplicationExtension | ||
import com.android.build.api.dsl.LibraryExtension | ||
import com.android.build.api.dsl.Lint | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
|
||
class AndroidLintConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
when { | ||
pluginManager.hasPlugin("com.android.application") -> | ||
configure<ApplicationExtension> { lint(Lint::configure) } | ||
|
||
pluginManager.hasPlugin("com.android.library") -> | ||
configure<LibraryExtension> { lint(Lint::configure) } | ||
|
||
else -> { | ||
pluginManager.apply("com.android.lint") | ||
configure<Lint>(Lint::configure) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun Lint.configure() { | ||
xmlReport = true | ||
checkDependencies = true | ||
} |
29 changes: 29 additions & 0 deletions
29
build-logic/convention/bin/main/AndroidRoomConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import androidx.room.gradle.RoomExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.mifos.libs | ||
|
||
class AndroidRoomConventionPlugin : Plugin<Project> { | ||
|
||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply("androidx.room") | ||
pluginManager.apply("com.google.devtools.ksp") | ||
|
||
extensions.configure<RoomExtension> { | ||
// 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. | ||
schemaDirectory("$projectDir/schemas") | ||
} | ||
|
||
dependencies { | ||
add("implementation", libs.findLibrary("room.runtime").get()) | ||
add("implementation", libs.findLibrary("room.ktx").get()) | ||
add("ksp", libs.findLibrary("room.compiler").get()) | ||
} | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
build-logic/convention/bin/main/AndroidTestConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import com.android.build.gradle.TestExtension | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.kotlin.dsl.configure | ||
import org.mifos.configureKotlinAndroid | ||
|
||
class AndroidTestConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("com.android.test") | ||
apply("org.jetbrains.kotlin.android") | ||
} | ||
|
||
extensions.configure<TestExtension> { | ||
configureKotlinAndroid(this) | ||
defaultConfig.targetSdk = 34 | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
build-logic/convention/bin/main/JvmLibraryConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.mifos.configureKotlinJvm | ||
|
||
class JvmLibraryConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
with(pluginManager) { | ||
apply("org.jetbrains.kotlin.jvm") | ||
apply("mifos.android.lint") | ||
} | ||
configureKotlinJvm() | ||
} | ||
} | ||
} |
Oops, something went wrong.