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

Retrofit 설정 #13

Merged
merged 6 commits into from
Jul 3, 2023
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
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.verify.detekt) apply false
}
16 changes: 14 additions & 2 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
plugins {
id("droidknights.kotlin.library")
id("droidknights.kotlin.hilt")
id("droidknights.android.library")
id("droidknights.android.hilt")
Comment on lines -2 to +3
Copy link
Member

Choose a reason for hiding this comment

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

왜 Diff로 잡혔을까요? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네트워크 외에도 로컬 관련 로직이 포함될 것 같아서 kotlin --> android 모듈로 변경되었습니다.

id("kotlinx-serialization")
}

android {
namespace = "com.droidknights.app2023.core.data"
}

dependencies {
implementation(libs.retrofit.core)
implementation(libs.retrofit.kotlin.serialization)
implementation(libs.okhttp.logging)
implementation(libs.kotlinx.serialization.json)
}
2 changes: 2 additions & 0 deletions core/data/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.droidknights.app2023.core.data.di

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
internal object ApiModule {
private const val BASE_URL = "https://raw.githubusercontent.com/"


@Provides
@Singleton
fun provideOkhttpClient(): OkHttpClient = OkHttpClient.Builder().build()

@Provides
@Singleton
fun provideRetrofit(
okHttpClient: OkHttpClient,
json: Json,
): Retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
Copy link
Member

Choose a reason for hiding this comment

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

Kotlinx serialization은 의존성만 추가하셨는데 ConverterFactory 등록도 같이 해주시면 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
.client(okHttpClient)
.build()

@Provides
@Singleton
fun provideJson(): Json = Json {
ignoreUnknownKeys = true
}
}
12 changes: 12 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ androidxComposeMaterial3 = "1.1.0"
androidxActivity = "1.7.2"
hilt = "2.46.1"

okhttp = "4.11.0"
retrofit = "2.9.0"
retrofitKotlinxSerializationJson = "1.0.0"
kotlinxSerializationJson = "1.5.1"

junit4 = "4.13.2"
kotlin = "1.8.21"

androidxTestExt = "1.1.4"
androidxEspresso = "3.5.0"
kotest = "5.6.2"
Expand Down Expand Up @@ -42,6 +48,11 @@ hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref
hilt-android-testing = { group = "com.google.dagger", name = "hilt-android-testing", version.ref = "hilt" }
hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }

okhttp-logging = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttp" }
retrofit-core = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
retrofit-kotlin-serialization = { group = "com.jakewharton.retrofit", name = "retrofit2-kotlinx-serialization-converter", version.ref = "retrofitKotlinxSerializationJson" }
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }

junit4 = { group = "junit", name = "junit", version.ref = "junit4" }
androidx-test-ext = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "androidxTestExt" }
androidx-test-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidxEspresso" }
Expand All @@ -62,5 +73,6 @@ android-application = { id = "com.android.application", version.ref = "androidGr
android-library = { id = "com.android.library", version.ref = "androidGradlePlugin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
verify-detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }