Skip to content

Commit

Permalink
feat: build-script 구현
Browse files Browse the repository at this point in the history
기초적인 build-script를 구현합니다. (의존성 추가나 필요한 Plugin로직들은 차차 추가예정)
-  Gradle 빌드 시, 먼저 build-logic이라는 외부 Gradle 빌드 스크립트를 포함하도록 선언합니다.


해당 코드는 아래의 레포지토리를 참조했습니다.
https://github.com/android/nowinandroid
  • Loading branch information
toastmeister1 committed Mar 5, 2023
1 parent 6f8c9ae commit 726f922
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 50 deletions.
44 changes: 0 additions & 44 deletions app/build.gradle

This file was deleted.

34 changes: 34 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id("kestrel.android.application")
id("kestrel.android.hilt")
}

android {
defaultConfig {
applicationId = "com.toastmeister1.kestrel"
targetSdk = 33
versionCode = 1
versionName = "1.0"

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

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

namespace = "com.toastmeister1.kestrel"
}

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.android.material)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit4)
androidTestImplementation(libs.androidx.test.ext)
androidTestImplementation(libs.androidx.test.espresso.core)
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".KestrelApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/toastmeister1/kestrel/KestrelApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.toastmeister1.kestrel

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


@HiltAndroidApp
internal class KestrelApplication : Application() {

override fun onCreate() {
super.onCreate()
}

}
2 changes: 2 additions & 0 deletions app/src/main/java/com/toastmeister1/kestrel/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.toastmeister1.kestrel

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
1 change: 1 addition & 0 deletions build-logic/convention/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
29 changes: 29 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
`kotlin-dsl`
}

group = "com.toastmeister1.kestrel.buildlogic"

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

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

gradlePlugin {
plugins {
register("androidApplication") {
id = "kestrel.android.application"
implementationClass = "AndroidApplicationConventionPlugin"
}

register("androidHilt") {
id = "kestrel.android.hilt"
implementationClass = "AndroidHiltConventionPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import com.android.build.api.dsl.ApplicationExtension
import com.toastmeister1.convention.configureKotlinAndroid
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class AndroidApplicationConventionPlugin : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.application")
apply("org.jetbrains.kotlin.android")
}

extensions.configure<ApplicationExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 33
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType

class AndroidHiltConventionPlugin : Plugin<Project> {

override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("dagger.hilt.android.plugin")
apply("org.jetbrains.kotlin.kapt")
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
"implementation"(libs.findLibrary("hilt.android").get())
"kapt"(libs.findLibrary("hilt.compiler").get())
"kaptAndroidTest"(libs.findLibrary("hilt.compiler").get())
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.toastmeister1.convention

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


/**
* Configure base Kotlin with Android options
*/
internal fun Project.configureKotlinAndroid(
commonExtension: CommonExtension<*, *, *, *>,
) {
commonExtension.apply {
compileSdk = 33

defaultConfig {
minSdk = 24
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf(
"-opt-in=kotlin.RequiresOptIn",
// Enable experimental coroutines APIs, including Flow
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=kotlin.Experimental"
)

jvmTarget = JavaVersion.VERSION_11.toString()
}
}
}

fun CommonExtension<*, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
(this as ExtensionAware).extensions.configure("kotlinOptions", block)
}
14 changes: 14 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
include(":convention")
6 changes: 0 additions & 6 deletions build.gradle

This file was deleted.

20 changes: 20 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
}

/**
* version catalog 'libs' ISSUE(refer to the link)
* https://github.com/gradle/gradle/issues/22797
*/
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.android.test) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.hilt) apply false
}
39 changes: 39 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[versions]
kotlin = "1.8.0"
hilt = "2.44.2"
androidGradlePlugin = "7.4.1"
androidxCore = "1.9.0"
androidxAppCompat = "1.6.1"
androidxConstraintLayout = "2.1.4"
androidxEspresso = "3.5.1"
androidxTestExt = "1.1.5"
junit4 = "4.13.2"
material = "1.8.0"


[libraries]
android-material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppCompat" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidxConstraintLayout" }
androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidxEspresso" }
androidx-test-ext = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "androidxTestExt" }
junit4 = { group = "junit", name = "junit", version.ref = "junit4" }
hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
hilt-android-testing = { group = "com.google.dagger", name = "hilt-android-testing", version.ref = "hilt" }
hilt-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }

# Dependencies of the included build-logic
android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" }
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }

[bundles]


[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
android-test = { id = "com.android.test", version.ref = "androidGradlePlugin" }
hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pluginManagement {
includeBuild("build-logic")
repositories {
google()
mavenCentral()
Expand Down

0 comments on commit 726f922

Please sign in to comment.