μλ
νμΈμ μ¬λ¬λΆ!
μ€λμ μ κ° μ΅κ·Ό νλ‘μ νΈμ λΉλ λ‘μ§(Build Logic)μ μ μ©νλ κ²½νμ λν΄μ 곡μ νλ €κ³ ν©λλ€.

1. λΉλ λ‘μ§(Build Logic)μ μ νμνμκΉ? π€
μ¬μ€ νλ‘μ νΈκ° μμ λλ Gradle μ€μ νλ 건 λ³λ‘ μ΄λ ΅μ§ μμ΅λλ€..
νμ§λ§ λͺ¨λμ΄ μ μ°¨ λμ΄λκ³ νλ¬κ·ΈμΈμ΄ λ§μ μ§λλ§λ€
κ°μ μμ μ λ°λ³΅νλ건 μ λ§ μ§μ₯μ΄μ£ ..β οΈ
μ΄ λ¬Έμ λ₯Ό ν΄κ²° ν μ μλ λ°©λ²μ΄ μμκΉ μκ°νλ€κ° λΉλ λ‘μ§μ μ μ©νκ² λμμ΅λλ€!
2. λΉλ λ‘μ§ (Build Logic) μ μ©κΈ° π
1. build-logic λͺ¨λ λ§λ€κΈ°
λͺ¨λμ Java or Kotlin Libraryλ‘ λ§λ€μ΄μ€λλ€.
2. build-logic Gradle μΈν νκΈ°
λͺ¨λ λ΄λΆμ build.gradle κ³Ό settings.gradleμ μμ±ν΄ μ£ΌμΈμ.
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
rootProject.name = "build-logic"
// build.gradle.kts
plugins {
`kotlin-dsl`
alias(libs.plugins.kotlin.serialization)
}
dependencies {
compileOnly(libs.kotlin.gradle.plugin)
compileOnly(libs.android.build.gradle)
compileOnly(libs.gradle.hilt)
}
3. Convention Plugin λ§λ€κΈ°
class AndroidLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) = with(target) {
pluginManager.apply {
apply("com.android.library")
apply("org.jetbrains.kotlin.android")
apply("org.jetbrains.kotlin.plugin.serialization")
}
extensions.configure<LibraryExtension> {
kotlinAndroidConfiguration(this)
buildConfigConfiguration(this)
defaultConfig {
consumerProguardFiles("consumer-rules.pro")
}
}
}
}
internal fun Project.kotlinAndroidConfiguration(
commonExtension: CommonExtension<*, *, *, *, *, *>,
) = with(commonExtension) {
compileSdk = 35
defaultConfig {
minSdk = 24
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
buildFeatures {
buildConfig = true
}
}
fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
}
fun Project.buildConfigConfiguration(
commonExtension: CommonExtension<*, *, *, *, *, *>,
) = with(commonExtension) {
buildTypes {
getByName("release") {
buildConfigField("boolean", "APP_DEBUG", false.toString())
}
getByName("debug") {
buildConfigField("boolean", "APP_DEBUG", true.toString())
}
}
}
4. build-logic Gradleμ plugin μΆκ°νκΈ°
gradlePlugin {
plugins {
register("androidLibrary") {
id = "com.android.library.convention"
implementationClass = "AndroidLibraryConventionPlugin"
}
}
5. λͺ¨λμ μ μ©νκΈ°
plugins {
id("com.android.library.convention")
}
android {
namespace = "com.test.example.module"
}
dependencies {
}
3. μ μ©κΈ°λ₯Ό λ§μΉλ©°...
Library λͺ¨λμ λν PluginλΏλ§ μλλΌ Compose , Hilt νΉμ Application Convention λ±μ λν΄μλ
νλ² μ μ©ν΄ λμΌλ©΄ κ°λ°μ΄ ν¨μ¬ νΈν΄μ§λ κ±Έ λλΌμ€ μ μμ κ²λλ€!
μλ NowInAndroid Github μν μ½λλ₯Ό λμΌλ‘ Build Logic μ μ©κΈ°λ λ§μΉκ² μ΅λλ€. πβοΈ
NowInAndroid Convention Plugin μμ