Skip to content

[KAN-48] BuildSrc 설정 #2

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

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
39 changes: 20 additions & 19 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
import Versions.JAVA_VERSION
import Versions.JAVA_VERSION_STRING

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
id(libs.plugins.android.application.get().pluginId)
id(libs.plugins.kotlin.android.get().pluginId)
id(libs.plugins.kotlin.compose.get().pluginId)
id(libs.plugins.ksp.get().pluginId)
id(libs.plugins.hilt.get().pluginId)
}

android {
namespace = "com.keeply.kr"
compileSdk = 36

setConfigs()

defaultConfig {
applicationId = "com.keeply.kr"
minSdk = 28
targetSdk = 36
versionCode = 1
versionName = "1.0"

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

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
setBuildType()
buildFeatures {
buildConfig = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JAVA_VERSION
targetCompatibility = JAVA_VERSION
}
kotlinOptions {
jvmTarget = "11"
jvmTarget = JAVA_VERSION_STRING
}
buildFeatures {
compose = true
Expand All @@ -58,4 +55,8 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)

implementation(libs.bundles.orbit)

hiltDependency()
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".KeeplyApplication"
android:theme="@style/Theme.Keeply">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Keeply">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/keeply/kr/KeeplyApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.keeply.kr

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class KeeplyApplication: Application()
2 changes: 2 additions & 0 deletions app/src/main/java/com/keeply/kr/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.keeply.kr.ui.theme.KeeplyTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
19 changes: 15 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath(libs.tools.build.gradle)
classpath(libs.kotlin.gradle.plugin)
classpath(libs.compose.compiler.gradle.plugin)
classpath(libs.hilt.android.gradle.plugin)
}
}
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.ksp) apply false
}
16 changes: 16 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
`kotlin-dsl`
}

repositories {
google()
mavenCentral()
}

dependencies {
implementation(libs.javapoet)
implementation(libs.tools.build.gradle)
implementation(libs.kotlin.gradle.plugin)
implementation(libs.compose.compiler.gradle.plugin)
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
7 changes: 7 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
44 changes: 44 additions & 0 deletions buildSrc/src/main/kotlin/BaseExtend.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Versions.COMPILE_SDK
import Versions.MIN_SDK
import Versions.TARGET_SDK
import com.android.build.gradle.BaseExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension

fun BaseAppModuleExtension.setConfigs() {
compileSdk = COMPILE_SDK

defaultConfig {
minSdk = MIN_SDK
targetSdk = TARGET_SDK

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

fun BaseExtension.setConfigs() {
compileSdkVersion(Versions.COMPILE_SDK)

defaultConfig {
minSdk = Versions.MIN_SDK
targetSdk = Versions.TARGET_SDK

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

fun BaseExtension.setBuildType() {
buildTypes {
getByName(BuildTask.DEBUG) {
isDebuggable = BuildTaskDebug.isDebuggable
isMinifyEnabled = BuildTaskDebug.isMinifyEnabled
}
getByName(BuildTask.RELEASE) {
isDebuggable = BuildTaskRelease.isDebuggable
isMinifyEnabled = BuildTaskRelease.isMinifyEnabled
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}
19 changes: 19 additions & 0 deletions buildSrc/src/main/kotlin/BuildTaskObject.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
interface BuildTask {
companion object {
const val DEBUG = "debug"
const val RELEASE = "release"
}

val isMinifyEnabled: Boolean
val isDebuggable: Boolean
}

object BuildTaskDebug : BuildTask {
override val isMinifyEnabled = false
override val isDebuggable = true
}

object BuildTaskRelease : BuildTask {
override val isMinifyEnabled = false
override val isDebuggable = false
}
50 changes: 50 additions & 0 deletions buildSrc/src/main/kotlin/DependencyExtend.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.kotlin.dsl.DependencyHandlerScope
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.the

fun Project.hiltDependency() {
project.dependencies {
implementation(libs.hilt.android)
ksp(libs.hilt.compiler)
}
}

private val Project.libs get() = the<LibrariesForLibs>()

private fun DependencyHandlerScope.implementation(vararg list: Any) {
list.forEach { add("implementation", it) }
}

private fun DependencyHandlerScope.debugImplementation(vararg list: Any) {
list.forEach { add("debugImplementation", it) }
}

private fun DependencyHandlerScope.kapt(vararg list: Any) {
list.forEach { add("kapt", it) }
}

private fun DependencyHandlerScope.ksp(vararg list: Any) {
list.forEach { add("ksp", it) }
}

private fun DependencyHandlerScope.testImplementation(vararg list: Any) {
list.forEach { add("testImplementation", it) }
}

private fun DependencyHandlerScope.testRuntimeOnly(vararg list: Any) {
list.forEach { add("testRuntimeOnly", it) }
}

private fun DependencyHandlerScope.androidTestImplementation(vararg list: Any) {
list.forEach { add("androidTestImplementation", it) }
}

private fun DependencyHandlerScope.androidTestRuntimeOnly(vararg list: Any) {
list.forEach { add("androidTestRuntimeOnly", it) }
}

private fun DependencyHandlerScope.annotationProcessor(vararg list: Any) {
list.forEach { add("annotationProcessor", it) }
}
9 changes: 9 additions & 0 deletions buildSrc/src/main/kotlin/ProjectExtention.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import org.gradle.api.Project
import java.util.Properties

fun Project.getBuildConfigProperty(propertyKey: String): String =
getLocalProperties("./local.properties").getProperty(propertyKey)

fun Project.getLocalProperties(fileName: String) = Properties().apply {
load(project.rootProject.file(fileName).inputStream())
}
10 changes: 10 additions & 0 deletions buildSrc/src/main/kotlin/Version.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import org.gradle.api.JavaVersion

object Versions {
const val COMPILE_SDK = 35
const val MIN_SDK = 26
const val TARGET_SDK = 35

val JAVA_VERSION = JavaVersion.VERSION_17
const val JAVA_VERSION_STRING = "17"
}
40 changes: 23 additions & 17 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import Versions.JAVA_VERSION
import Versions.JAVA_VERSION_STRING

plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
id(libs.plugins.android.library.get().pluginId)
id(libs.plugins.kotlin.android.get().pluginId)
id(libs.plugins.ksp.get().pluginId)
id(libs.plugins.hilt.get().pluginId)
}

android {
namespace = "com.keeply.data"
compileSdk = 36

setConfigs()
defaultConfig {
minSdk = 28

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
buildConfigField(
"String",
"BASE_URL",
getBuildConfigProperty("BASE_URL")
)
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
setBuildType()
buildFeatures {
buildConfig = true
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JAVA_VERSION
targetCompatibility = JAVA_VERSION
}
kotlinOptions {
jvmTarget = "11"
jvmTarget = JAVA_VERSION_STRING
}
}

Expand All @@ -41,4 +43,8 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
implementation(libs.bundles.retrofit)
implementation(libs.serialization.json)

hiltDependency()
}
Loading