-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added build-logic and refactor plugin #2094
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fff8516
feat: added build-logic and refactor plugin
Aditya-gupta99 c49478e
feat: added build-logic and refactor plugin
Aditya-gupta99 4409ffd
fix: fix test and lint check fails
Aditya-gupta99 f14af1b
fix: code clean up
Aditya-gupta99 851450c
fix: remove crashlytic for sspecific flavors
Aditya-gupta99 9aa889f
Merge branch 'master' into build_logic
Aditya-gupta99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
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,33 @@ | ||
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") | ||
} | ||
|
||
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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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) | ||
} | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
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.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 | ||
// 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this, we want Crashlytics for all the flavour