Skip to content

[CT-1-2] hilt 추가, ktlint 추가, buildSrc 작성 #10

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 23 additions & 27 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id(Plugin.ANDROID_APPLICATION)
id(Plugin.KOTLIN_ANDROID)
id(Plugin.KTLINT)
id(Plugin.HILT)
kotlin(Plugin.KAPT)
}

android {
Expand All @@ -25,22 +28,16 @@ android {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
jvmTarget = "17"
}
packaging {
resources {
Expand All @@ -54,19 +51,18 @@ dependencies {
implementation(project(path = ":domain"))
implementation(project(path = ":presentation"))

implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-tooling")
debugImplementation("androidx.compose.ui:ui-test-manifest")
implementation(Dependency.HILT)
kapt(Dependency.HILT_COMPILER)

implementation(Dependency.ANDROIDX_CORE)
testImplementation(Dependency.Test.JUNIT)
androidTestImplementation(Dependency.Test.JUNIT_EXT)
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
additionalEditorconfig.set(
mapOf(
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
),
)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.yessorae.chartrainer

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand All @@ -21,4 +19,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.yessorae.chartrainer", appContext.packageName)
}
}
}
3 changes: 2 additions & 1 deletion 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=".CharTrainerApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -13,7 +14,7 @@
android:theme="@style/Theme.Chartrainer"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name="com.yessorae.presentation.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Chartrainer">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.yessorae.chartrainer

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

@HiltAndroidApp
class CharTrainerApplication : Application()
5 changes: 2 additions & 3 deletions app/src/test/java/com/yessorae/chartrainer/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.yessorae.chartrainer

import org.junit.Assert.assertEquals
import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
Expand All @@ -14,4 +13,4 @@ class ExampleUnitTest {
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
}
12 changes: 7 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.1.2" apply false
id("org.jetbrains.kotlin.android") version "1.8.10" apply false
id("org.jetbrains.kotlin.jvm") version "1.8.10" apply false
id("com.android.library") version "8.1.2" apply false
}
id(Plugin.ANDROID_APPLICATION) version Plugin.Version.ANDROID_APPLICATION apply false
id(Plugin.KOTLIN_ANDROID) version Plugin.Version.KOTLIN_ANDROID apply false
id(Plugin.KOTLIN_JVM) version Plugin.Version.KOTLIN_JVM apply false
id(Plugin.ANDROID_LIBRARY) version Plugin.Version.ANDROID_LIBRARY apply false
id(Plugin.KTLINT) version Plugin.Version.KTLINT
id(Plugin.HILT) version Plugin.Version.HILT apply false
}
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
`kotlin-dsl`
}

repositories {
google()
mavenCentral()
}
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Config {
const val COMPOSE_COMPILER_VERSION = "1.4.3"
}
27 changes: 27 additions & 0 deletions buildSrc/src/main/kotlin/Dependency.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
object Dependency {
const val HILT = "com.google.dagger:hilt-android:2.44"
const val HILT_COMPILER = "com.google.dagger:hilt-android-compiler:2.44"
const val JAVAX_INJECT = "javax.inject:javax.inject:1"

const val ANDROIDX_CORE = "androidx.core:core-ktx:1.9.0" // 1.13.1

object Compose {
const val BOM = "androidx.compose:compose-bom:2023.03.00"
const val UI = "androidx.compose.ui:ui"
const val UI_GRAPHICS = "androidx.compose.ui:ui-graphics"
const val MATERIAL_3 = "androidx.compose.material3:material3"
const val LIFECYCLE_RUNTIME = "androidx.lifecycle:lifecycle-runtime-ktx:2.7.0"
const val ACTIVITY_COMPOSE = "androidx.activity:activity-compose:1.8.2"

const val UI_TOOLING = "androidx.compose.ui:ui-tooling"
const val UI_TOOLING_PREVIEW = "androidx.compose.ui:ui-tooling-preview"
const val JUNIT = "androidx.compose.ui:ui-test-junit4"
const val UI_TEST_MANIFEST = "androidx.compose.ui:ui-test-manifest"
}

object Test {
const val JUNIT = "junit:junit:4.13.2"
const val JUNIT_EXT = "androidx.test.ext:junit:1.1.5"
}
}

18 changes: 18 additions & 0 deletions buildSrc/src/main/kotlin/Plugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
object Plugin {
const val ANDROID_APPLICATION = "com.android.application"
const val KOTLIN_JVM = "org.jetbrains.kotlin.jvm"
const val KOTLIN_ANDROID = "org.jetbrains.kotlin.android"
const val ANDROID_LIBRARY = "com.android.library"
const val KTLINT = "org.jlleitschuh.gradle.ktlint"
const val HILT = "com.google.dagger.hilt.android"
const val KAPT = "kapt"

object Version {
const val ANDROID_APPLICATION = "8.1.2"
const val KOTLIN_ANDROID = "1.8.10"
const val KOTLIN_JVM = "1.8.10"
const val ANDROID_LIBRARY = "8.1.2"
const val KTLINT = "12.1.1"
const val HILT = "2.44"
}
}
30 changes: 16 additions & 14 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id(Plugin.ANDROID_LIBRARY)
id(Plugin.KOTLIN_ANDROID)
id(Plugin.KTLINT)
id(Plugin.HILT)
kotlin(Plugin.KAPT)
}

android {
namespace = "com.yessorae.data"
compileSdk = 33
compileSdk = 34

defaultConfig {
minSdk = 24
Expand All @@ -19,26 +22,25 @@ android {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q; 8에서 17로 변경할 때 어떤 이점이 있을까요?

Copy link
Collaborator Author

@nosorae nosorae May 11, 2024

Choose a reason for hiding this comment

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

명확한 이점을 찾아 올린 것은 아닙니다.
compileDebugJavaWithJavac와 kaptGenerateStubsDebugKotlin 빌드에러를 해결하기 위해 수정했습니다.

에러내용:
Caused by: org.gradle.api.GradleException: 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.

targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
}

dependencies {
implementation(project(path = ":domain"))

implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
implementation(Dependency.HILT)
kapt(Dependency.HILT_COMPILER)

testImplementation(Dependency.Test.JUNIT)
androidTestImplementation(Dependency.Test.JUNIT_EXT)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.yessorae.data

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
Expand All @@ -21,4 +19,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.yessorae.data.test", appContext.packageName)
}
}
}
5 changes: 2 additions & 3 deletions data/src/test/java/com/yessorae/data/ExampleUnitTest.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.yessorae.data

import org.junit.Assert.assertEquals
import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
Expand All @@ -14,4 +13,4 @@ class ExampleUnitTest {
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
}
15 changes: 11 additions & 4 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@


plugins {
id("java-library")
id("org.jetbrains.kotlin.jvm")
id(Plugin.KOTLIN_JVM)
id(Plugin.KTLINT)
}

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

dependencies {
implementation(Dependency.JAVAX_INJECT)
}
Loading
Loading