Skip to content
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

[REFACTOR/#171] buildSrc에서 build-logic 마이그레이션 #172

Merged
merged 24 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
61d9a8f
[ADD/#171] libs.versions.toml 세팅
Marchbreeze Nov 19, 2024
4621224
[ADD/#171] build-logic 모듈 세팅
Marchbreeze Nov 19, 2024
6f46ed6
[ADD/#171] Convention 모듈 추가
Marchbreeze Nov 19, 2024
d3ad633
[ADD/#171] setting에 build-logic 등록
Marchbreeze Nov 19, 2024
f89f045
[ADD/#171] convention 모듈 build gradle 설정
Marchbreeze Nov 19, 2024
fa958a2
[ADD/#171] 프로젝트 build Gradle 플러그인 설정
Marchbreeze Nov 19, 2024
205d670
[FIX/#171] 안드로이드 코루틴 분리
Marchbreeze Nov 19, 2024
36f3d80
[ADD/#171] Convention Ext 추가
Marchbreeze Nov 19, 2024
da6f9f8
[ADD/#171] Gradle Plugin 설정
Marchbreeze Nov 19, 2024
468161a
[ADD/#171] project configuration 설정
Marchbreeze Nov 20, 2024
c5332e3
[FEAT/#171] 플러그인 초기 설정
Marchbreeze Nov 20, 2024
528ee50
[FEAT/#171] 플러그인 고도화
Marchbreeze Nov 20, 2024
44b55b6
[ADD/#171] build Gradle에 플러그인 등록
Marchbreeze Nov 20, 2024
111a42a
[FEAT/#171] 각 모듈 build gradle 플러그인 적용
Marchbreeze Nov 20, 2024
51111ae
[REFACTOR/#171] buildSrc 삭제 및 오류 수정
Marchbreeze Nov 20, 2024
c092532
[ADD/#171] Version 플러그인 설정
Marchbreeze Nov 21, 2024
3f0fbf9
[FIX/#171] 테스트 라이브러리 버전 업데이트
Marchbreeze Nov 21, 2024
e57c043
[FIX/#171] AGP & gradle version 조정
Marchbreeze Nov 21, 2024
19b3bf8
[FIX/#171] 각 모듈 androidLibrary 플러그인 관련 오류 수정
Marchbreeze Nov 21, 2024
d1f6fc8
[FIX/#171] buildConfigField 위치 변경
Marchbreeze Nov 22, 2024
be09c80
[FIX/#171] kotlin.plugin.serialization 추가
Marchbreeze Nov 22, 2024
bb8d71f
[FIX/#171] 미사용 androidx 라이브러리 제거
Marchbreeze Nov 22, 2024
fd8b074
[FIX/#171] Test implementation 수정
Marchbreeze Nov 22, 2024
1d237c3
[FIX/#171] ExtensionContainerExt 삭제
Marchbreeze Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 9 additions & 79 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties

plugins {
id("com.android.application")
kotlin("android")
kotlin("kapt")
id("kotlin-parcelize")
id("dagger.hilt.android.plugin")
id("kr.genti.androidApplication")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 매번 이렇게 하드코딩하는것이 휴먼 에러를 발생시킬 수 있다고 생각해서 libs.version.toml의 플러그인으로 등록해두는 편입니다. 휴먼에러 방지용!!

// libs.version.toml
[plugins]
genti-androidApplication = { id = "kr.genti.androidApplication", version = "unspecified" }

// build.gradle.kts
plugins {
    alias(libs.plugins.genti.androidApplication)
}

id("com.google.gms.google-services")
id("com.google.firebase.crashlytics")
}

android {
namespace = Constants.packageName
compileSdk = Constants.compileSdk

defaultConfig {
applicationId = Constants.packageName
minSdk = Constants.minSdk
targetSdk = Constants.targetSdk
versionCode = Constants.versionCode
versionName = Constants.versionName

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

buildConfigField(
"String",
"NATIVE_APP_KEY",
Expand Down Expand Up @@ -57,72 +42,17 @@ android {
"AMPLITUDE_KEY",
gradleLocalProperties(rootDir).getProperty("amplitude.api.key"),
)

isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
}
}

compileOptions {
sourceCompatibility = Versions.javaVersion
targetCompatibility = Versions.javaVersion
}

kotlinOptions {
jvmTarget = Versions.jvmVersion
}

buildFeatures {
buildConfig = true
dataBinding = true
viewBinding = true
}
}

dependencies {
implementation(project(":core"))
implementation(project(":data"))
implementation(project(":domain"))
implementation(project(":presentation"))

KotlinDependencies.run {
implementation(kotlin)
implementation(coroutines)
implementation(jsonSerialization)
}

AndroidXDependencies.run {
implementation(coreKtx)
implementation(appCompat)
implementation(hilt)
}

KaptDependencies.run {
kapt(hiltCompiler)
}

TestDependencies.run {
testImplementation(jUnit)
androidTestImplementation(androidTest)
androidTestImplementation(espresso)
}

RetrofitDependencies.run {
implementation(platform(okHttpBom))
implementation(okHttp)
implementation(okHttpLoggingInterceptor)
implementation(retrofit)
implementation(retrofitJsonConverter)
}

ThirdPartyDependencies.run {
implementation(timber)
}

KakaoDependencies.run {
implementation(user)
}
implementation(projects.core)
implementation(projects.data)
implementation(projects.domain)
implementation(projects.presentation)

implementation(platform(libs.okhttp.bom))
implementation(libs.bundles.networking)
implementation(libs.kakao)
}
47 changes: 47 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
plugins {
`kotlin-dsl`
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

dependencies {
implementation(libs.android.gradlePlugin)
implementation(libs.kotlin.gradlePlugin)
}

gradlePlugin {
plugins {
register("AndroidApplicationPlugin") {
id = "kr.genti.androidApplication"
implementationClass = "kr.genti.convention.plugin.AndroidApplicationPlugin"
}
register("AndroidLibraryPlugin") {
id = "kr.genti.androidLibrary"
implementationClass = "kr.genti.convention.plugin.AndroidLibraryPlugin"
}
register("JavaLibraryPlugin") {
id = "kr.genti.javaLibrary"
implementationClass = "kr.genti.convention.plugin.JavaLibraryPlugin"
}

register("KotlinPlugin") {
id = "kr.genti.kotlin"
implementationClass = "kr.genti.convention.plugin.KotlinPlugin"
}
register("HiltPlugin") {
id = "kr.genti.hilt"
implementationClass = "kr.genti.convention.plugin.HiltPlugin"
}
register("TestPlugin") {
id = "kr.genti.test"
implementationClass = "kr.genti.convention.plugin.TestPlugin"
}
register("versionPlugin") {
id = "kr.genti.version"
implementationClass = "kr.genti.convention.plugin.VersionPlugin"
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 단순한 궁금증인데, 저는 모든 버전을 libs.version.toml에서 관리하는 방법을 주로 사용해요.
하나의 파일에서 모든 버전을 관리한다면 추후 버전을 변경할 때 찾기 쉬울 것이라는 생각에 그러한 방식을 사용하는데 따로 Constants를 사용하신 이유나 장점이 있나요??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libs.version.toml에서는 implementation 관련된 버전만 관리하는게 편할 것 같아서 했습니다!
또한 libs.version.toml에서 저장하면 build-logic에서 getVersion 확장함수로 매번 가져와야하는데, 아예 build-logic 모듈 안에서 관리하게 된다면 접근할 필요가 없어진다고 생각했어요 (gradle에 활용되는 버전들을 모두 빌드로직에 옮겨두었기 때문에)

Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package kr.genti.convention

import org.gradle.api.JavaVersion

object Constants {
const val packageName = "kr.genti.android"

const val compileSdk = 34
const val minSdk = 28
const val targetSdk = 34

const val versionCode = 18
const val versionName = "2.0.2"

const val jvmVersion = "17"
val JAVA_VERSION = JavaVersion.VERSION_17
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kr.genti.convention.config

import kr.genti.convention.extension.getLibrary
import kr.genti.convention.extension.implementation
import kr.genti.convention.plugin.HiltPlugin
import kr.genti.convention.plugin.KotlinPlugin
import kr.genti.convention.plugin.TestPlugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType

fun Project.configureAndroidCommonPlugin() {
apply<KotlinPlugin>()
apply<HiltPlugin>()
apply<TestPlugin>()
with(plugins) {
apply("kotlin-parcelize")
apply("org.jetbrains.kotlin.plugin.serialization")
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
implementation(libs.getLibrary("material-design"))
implementation(libs.getLibrary("timber"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kr.genti.convention.extension

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.plugins.ExtensionAware
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions

fun CommonExtension<*, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package kr.genti.convention.extension

import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.ConfigurableFileTree
import org.gradle.api.provider.Provider
import org.gradle.kotlin.dsl.DependencyHandlerScope

fun DependencyHandlerScope.implementation(project: Project) {
"implementation"(project)
}

fun DependencyHandlerScope.implementation(provider: Provider<*>) {
"implementation"(provider)
}

fun DependencyHandlerScope.implementation(fileTree: ConfigurableFileTree) {
"implementation"(fileTree)
}

fun DependencyHandlerScope.implementation(fileCollection: ConfigurableFileCollection) {
"implementation"(fileCollection)
}

fun DependencyHandlerScope.debugImplementation(provider: Provider<*>) {
"debugImplementation"(provider)
}

fun DependencyHandlerScope.releaseImplementation(provider: Provider<*>) {
"releaseImplementation"(provider)
}

fun DependencyHandlerScope.kapt(provider: Provider<*>) {
"kapt"(provider)
}

fun DependencyHandlerScope.coreLibraryDesugaring(provider: Provider<*>) {
"coreLibraryDesugaring"(provider)
}

fun DependencyHandlerScope.androidTestImplementation(provider: Provider<*>) {
"androidTestImplementation"(provider)
}

fun DependencyHandlerScope.testImplementation(provider: Provider<*>) {
"testImplementation"(provider)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package kr.genti.convention.extension

import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

val Project.libs: VersionCatalog
get() = extensions.getByType<VersionCatalogsExtension>().named("libs")
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package kr.genti.convention.extension

import org.gradle.api.artifacts.ExternalModuleDependencyBundle
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.provider.Provider

fun VersionCatalog.getBundle(bundleName: String): Provider<ExternalModuleDependencyBundle> =
findBundle(bundleName).orElseThrow {
NoSuchElementException("Bundle with name $bundleName not found in the catalog")
}

fun VersionCatalog.getLibrary(libraryName: String): Provider<MinimalExternalModuleDependency> =
findLibrary(libraryName).orElseThrow {
NoSuchElementException("Library with name $libraryName not found in the catalog")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package kr.genti.convention.plugin

import com.android.build.api.dsl.ApplicationExtension
import kr.genti.convention.Constants
import kr.genti.convention.config.configureAndroidCommonPlugin
import kr.genti.convention.extension.kotlinOptions
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class AndroidApplicationPlugin : Plugin<Project> {
override fun apply(target: Project) =
with(target) {
with(pluginManager) {
apply("com.android.application")
}

extensions.configure<ApplicationExtension> {
configureAndroidCommonPlugin()

namespace = Constants.packageName
compileSdk = Constants.compileSdk

defaultConfig {
applicationId = Constants.packageName
targetSdk = Constants.targetSdk
minSdk = Constants.minSdk
versionCode = Constants.versionCode
versionName = Constants.versionName

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility = Constants.JAVA_VERSION
targetCompatibility = Constants.JAVA_VERSION
}

kotlinOptions {
jvmTarget = Constants.jvmVersion
}

buildFeatures {
buildConfig = true
viewBinding = true
dataBinding = true
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
}
}
}
}
}
Loading
Loading