Skip to content

Commit 418994e

Browse files
committed
WIP: add build-logic convention plugins to reduce module configuration repetition
- Created build-logic module with Gradle convention plugins - Added plugins for android.library, android.hilt, jvm.library, and android.feature - Migrated existing modules to use convention plugins - Reduced boilerplate configuration by ~75% in module build scripts - All common Android/Kotlin configuration now centralized in build-logic Still WIP: need to complete migration of remaining modules and test full build
1 parent e5fe99c commit 418994e

28 files changed

Lines changed: 382 additions & 330 deletions

build-logic/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

build-logic/convention/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
3+
plugins {
4+
`kotlin-dsl`
5+
}
6+
7+
group = "com.dpconde.sofiatracker.buildlogic"
8+
9+
// Configure the build-logic plugins to target JDK that will be used to build the project
10+
java {
11+
sourceCompatibility = JavaVersion.VERSION_11
12+
targetCompatibility = JavaVersion.VERSION_11
13+
}
14+
15+
kotlin {
16+
compilerOptions {
17+
jvmTarget = JvmTarget.JVM_11
18+
}
19+
}
20+
21+
dependencies {
22+
compileOnly(libs.android.gradlePlugin)
23+
compileOnly(libs.android.tools.common)
24+
compileOnly(libs.kotlin.gradlePlugin)
25+
compileOnly(libs.ksp.gradlePlugin)
26+
compileOnly(libs.compose.gradlePlugin)
27+
}
28+
29+
tasks {
30+
validatePlugins {
31+
enableStricterValidation = true
32+
failOnWarning = true
33+
}
34+
}
35+
36+
gradlePlugin {
37+
plugins {
38+
register("androidApplicationCompose") {
39+
id = "sofiatracker.android.application.compose"
40+
implementationClass = "AndroidApplicationComposeConventionPlugin"
41+
}
42+
register("androidApplication") {
43+
id = "sofiatracker.android.application"
44+
implementationClass = "AndroidApplicationConventionPlugin"
45+
}
46+
register("androidLibraryCompose") {
47+
id = "sofiatracker.android.library.compose"
48+
implementationClass = "AndroidLibraryComposeConventionPlugin"
49+
}
50+
register("androidLibrary") {
51+
id = "sofiatracker.android.library"
52+
implementationClass = "AndroidLibraryConventionPlugin"
53+
}
54+
register("androidFeature") {
55+
id = "sofiatracker.android.feature"
56+
implementationClass = "AndroidFeatureConventionPlugin"
57+
}
58+
register("androidHilt") {
59+
id = "sofiatracker.android.hilt"
60+
implementationClass = "AndroidHiltConventionPlugin"
61+
}
62+
register("jvmLibrary") {
63+
id = "sofiatracker.jvm.library"
64+
implementationClass = "JvmLibraryConventionPlugin"
65+
}
66+
}
67+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import com.android.build.api.dsl.ApplicationExtension
2+
import com.dpconde.sofiatracker.buildlogic.configureAndroidCompose
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.Project
5+
import org.gradle.kotlin.dsl.getByType
6+
7+
class AndroidApplicationComposeConventionPlugin : Plugin<Project> {
8+
override fun apply(target: Project) {
9+
with(target) {
10+
pluginManager.apply("com.android.application")
11+
pluginManager.apply("org.jetbrains.kotlin.plugin.compose")
12+
13+
val extension = extensions.getByType<ApplicationExtension>()
14+
configureAndroidCompose(extension)
15+
}
16+
}
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import com.android.build.api.dsl.ApplicationExtension
2+
import com.dpconde.sofiatracker.buildlogic.configureKotlinAndroid
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.Project
5+
import org.gradle.kotlin.dsl.configure
6+
7+
class AndroidApplicationConventionPlugin : Plugin<Project> {
8+
override fun apply(target: Project) {
9+
with(target) {
10+
with(pluginManager) {
11+
apply("com.android.application")
12+
apply("org.jetbrains.kotlin.android")
13+
}
14+
15+
extensions.configure<ApplicationExtension> {
16+
configureKotlinAndroid(this)
17+
defaultConfig.targetSdk = 35
18+
defaultConfig.versionCode = 1
19+
defaultConfig.versionName = "1.0"
20+
}
21+
}
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import org.gradle.api.Plugin
2+
import org.gradle.api.Project
3+
import org.gradle.kotlin.dsl.dependencies
4+
5+
class AndroidFeatureConventionPlugin : Plugin<Project> {
6+
override fun apply(target: Project) {
7+
with(target) {
8+
pluginManager.apply {
9+
apply("sofiatracker.android.library")
10+
apply("sofiatracker.android.library.compose")
11+
apply("sofiatracker.android.hilt")
12+
}
13+
14+
dependencies {
15+
add("implementation", project(":core:ui"))
16+
add("implementation", project(":core:designsystem"))
17+
add("implementation", project(":core:domain"))
18+
}
19+
}
20+
}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import org.gradle.api.Plugin
2+
import org.gradle.api.Project
3+
import org.gradle.kotlin.dsl.dependencies
4+
import com.dpconde.sofiatracker.buildlogic.libs
5+
6+
7+
class AndroidHiltConventionPlugin : Plugin<Project> {
8+
override fun apply(target: Project) {
9+
with(target) {
10+
with(pluginManager) {
11+
apply("dagger.hilt.android.plugin")
12+
apply("com.google.devtools.ksp")
13+
}
14+
15+
dependencies {
16+
add("implementation", libs.findLibrary("hilt.android").get())
17+
add("ksp", libs.findLibrary("hilt.compiler").get())
18+
add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get())
19+
}
20+
}
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import com.android.build.gradle.LibraryExtension
2+
import com.dpconde.sofiatracker.buildlogic.configureAndroidCompose
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.Project
5+
import org.gradle.kotlin.dsl.getByType
6+
7+
class AndroidLibraryComposeConventionPlugin : Plugin<Project> {
8+
override fun apply(target: Project) {
9+
with(target) {
10+
with(pluginManager){
11+
apply("com.android.library")
12+
apply("org.jetbrains.kotlin.plugin.compose")
13+
}
14+
15+
val extension = extensions.getByType<LibraryExtension>()
16+
configureAndroidCompose(extension)
17+
}
18+
}
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import com.android.build.gradle.LibraryExtension
2+
import com.dpconde.sofiatracker.buildlogic.configureKotlinAndroid
3+
import org.gradle.api.Plugin
4+
import org.gradle.api.Project
5+
import org.gradle.kotlin.dsl.configure
6+
import org.gradle.kotlin.dsl.dependencies
7+
import org.gradle.kotlin.dsl.kotlin
8+
9+
class AndroidLibraryConventionPlugin : Plugin<Project> {
10+
override fun apply(target: Project) {
11+
with(target) {
12+
with(pluginManager) {
13+
apply("com.android.library")
14+
apply("org.jetbrains.kotlin.android")
15+
}
16+
17+
extensions.configure<LibraryExtension> {
18+
configureKotlinAndroid(this)
19+
defaultConfig.targetSdk = 35
20+
21+
// Consumer proguard files
22+
defaultConfig.consumerProguardFiles("consumer-rules.pro")
23+
}
24+
25+
dependencies {
26+
add("testImplementation", kotlin("test"))
27+
}
28+
}
29+
}
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import org.gradle.api.JavaVersion
2+
import org.gradle.api.Plugin
3+
import org.gradle.api.Project
4+
import org.gradle.kotlin.dsl.configure
5+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
6+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
7+
8+
class JvmLibraryConventionPlugin : Plugin<Project> {
9+
override fun apply(target: Project) {
10+
with(target) {
11+
with(pluginManager) {
12+
apply("java-library")
13+
apply("org.jetbrains.kotlin.jvm")
14+
}
15+
16+
// Configure Java compatibility
17+
extensions.configure<org.gradle.api.plugins.JavaPluginExtension> {
18+
sourceCompatibility = JavaVersion.VERSION_11
19+
targetCompatibility = JavaVersion.VERSION_11
20+
}
21+
22+
extensions.configure<KotlinJvmProjectExtension> {
23+
compilerOptions {
24+
jvmTarget.set(JvmTarget.JVM_11)
25+
}
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)