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

Use the official Kotlin Serialization converter from Retrofit and remove references to Moshi #20

Merged
merged 6 commits into from
May 16, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Go to the [Releases](https://github.com/skydoves/pokedex-compose/releases) to do
- Repository Pattern: Acts as a mediator between different data sources and the application's business logic.
- [Retrofit2 & OkHttp3](https://github.com/square/retrofit): Constructs REST APIs and facilitates paging network data retrieval.
- [Sandwich](https://github.com/skydoves/Sandwich): Adaptable and lightweight sealed API library designed for handling API responses and exceptions in Kotlin for Retrofit, Ktor, and Kotlin Multiplatform.
- [Moshi](https://github.com/square/moshi/): A modern JSON library compatible with Kotlin and Java.
- [Kotlin Serialization](https://github.com/Kotlin/kotlinx.serialization): Kotlin multiplatform / multi-format reflectionless serialization.
- [ksp](https://github.com/google/ksp): Kotlin Symbol Processing API for code generation and analysis.
- [Turbine](https://github.com/cashapp/turbine): A small testing library for kotlinx.coroutines Flow.
- [Landscapist Glide](https://github.com/skydoves/landscapist#glide), [animation](https://github.com/skydoves/landscapist#animation), [placeholder](https://github.com/skydoves/landscapist#placeholder): A pluggable, highly optimized Jetpack Compose and Kotlin Multiplatform image loading library that fetches and displays network images with Glide, Coil, and Fresco.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,24 @@ internal fun Project.configureAndroidCompose(
}
}

private fun Project.buildComposeMetricsParameters(): List<String> {
val metricParameters = mutableListOf<String>()
private fun Project.buildComposeMetricsParameters(): List<String> = buildList {
val enableMetricsProvider = project.providers.gradleProperty("enableComposeCompilerMetrics")
val enableMetrics = (enableMetricsProvider.orNull == "true")
if (enableMetrics) {
val metricsFolder = File(project.buildDir, "compose-metrics")
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + metricsFolder.absolutePath
val metricsFolder = project.layout.buildDirectory.dir("compose-metrics").get()
add("-P")
add(
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=$metricsFolder"
)
}

val enableReportsProvider = project.providers.gradleProperty("enableComposeCompilerReports")
val enableReports = (enableReportsProvider.orNull == "true")
if (enableReports) {
val reportsFolder = File(project.buildDir, "compose-reports")
metricParameters.add("-P")
metricParameters.add(
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + reportsFolder.absolutePath
val reportsFolder = project.layout.buildDirectory.dir("compose-reports").get()
add("-P")
add(
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=$reportsFolder"
)
}
return metricParameters.toList()
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
alias(libs.plugins.android.test) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.kotlinx.serialization) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.hilt.plugin) apply false
alias(libs.plugins.spotless)
Expand Down
3 changes: 1 addition & 2 deletions core/data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ dependencies {
api(libs.kotlinx.immutable.collection)

// coroutines
implementation(libs.kotlinx.coroutines)
testImplementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.coroutines.android)
testImplementation(libs.kotlinx.coroutines.test)

// network
Expand Down
5 changes: 2 additions & 3 deletions core/database/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ dependencies {
testImplementation(projects.core.test)

// coroutines
implementation(libs.kotlinx.coroutines)
testImplementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.coroutines.android)
testImplementation(libs.kotlinx.coroutines.test)

// database
implementation(libs.androidx.room.runtime)
implementation(libs.androidx.room.ktx)
ksp(libs.androidx.room.compiler)
testImplementation(libs.androidx.arch.core)
testImplementation(libs.androidx.arch.core.testing)

// json parsing
implementation(libs.kotlinx.serialization.json)
Expand Down
2 changes: 1 addition & 1 deletion core/model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
// compose stable marker
compileOnly(libs.compose.stable.marker)

// moshi
// Kotlin Serialization for Json
implementation(libs.kotlinx.serialization.json)

// kotlinx
Expand Down
2 changes: 1 addition & 1 deletion core/navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
dependencies {
implementation(projects.core.model)

implementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.coroutines.android)

implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.animation)
Expand Down
6 changes: 3 additions & 3 deletions core/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ dependencies {
testImplementation(projects.core.test)

// coroutines
implementation(libs.kotlinx.coroutines)
testImplementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.coroutines.android)
testImplementation(libs.kotlinx.coroutines.test)

// network
implementation(libs.sandwich)
implementation(libs.bundles.retrofitBundle)
testImplementation(libs.androidx.arch.core)
testImplementation(libs.okhttp.mockwebserver)
testImplementation(libs.androidx.arch.core.testing)

// json parsing
implementation(libs.kotlinx.serialization.json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.skydoves.pokedex.compose.core.network.di

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.skydoves.pokedex.compose.core.network.service.PokedexClient
import com.skydoves.pokedex.compose.core.network.service.PokedexService
import com.skydoves.pokedex.core.network.BuildConfig
Expand All @@ -30,6 +29,7 @@ import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.kotlinx.serialization.asConverterFactory
import javax.inject.Singleton

@Module
Expand All @@ -38,7 +38,7 @@ internal object NetworkModule {

@Singleton
@Provides
fun provideJson() = Json {
fun provideJson(): Json = Json {
ignoreUnknownKeys = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.skydoves.pokedex.compose.core.network

import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.skydoves.pokedex.compose.core.test.MainCoroutinesRule
import com.skydoves.sandwich.retrofit.adapters.ApiResponseCallAdapterFactory
import kotlinx.serialization.json.Json
Expand All @@ -32,6 +31,7 @@ import org.junit.Rule
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import retrofit2.Retrofit
import retrofit2.converter.kotlinx.serialization.asConverterFactory
import java.nio.charset.StandardCharsets

@RunWith(JUnit4::class)
Expand Down
2 changes: 1 addition & 1 deletion core/test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {

dependencies {
implementation(projects.core.model)
implementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.coroutines.test)
implementation(libs.junit)
}
16 changes: 7 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ composeStableMarker = "1.0.4"
kotlinxSerializationJson = "1.6.3"
hilt = "2.51.1"
retrofit = "2.11.0"
retrofitKotlinxSerializationJson = "1.0.0"
okHttp = "4.12.0"
sandwich = "2.0.7"
landscapist = "2.3.3"
moshi = "1.15.1"
coroutines = "1.8.0"
profileInstaller = "1.3.1"
macroBenchmark = "1.2.3"
Expand All @@ -43,7 +41,7 @@ baselineprofile = "1.2.3"
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "androidxRoom" }
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "androidxRoom" }
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "androidxRoom" }
androidx-arch-core = { module = "androidx.arch.core:core-testing", version.ref = "androidxArchCore" }
androidx-arch-core-testing = { module = "androidx.arch.core:core-testing", version.ref = "androidxArchCore" }
androidx-startup = { module = "androidx.startup:startup-runtime", version.ref = "androidXStartup" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivity" }
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "androidxComposeNavigation" }
Expand All @@ -70,10 +68,10 @@ hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hil
hilt-testing = { module = "com.google.dagger:hilt-android-testing", version.ref = "hilt" }
sandwich = { module = "com.github.skydoves:sandwich-retrofit", version.ref = "sandwich" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit-kotlin-serialization = { group = "com.jakewharton.retrofit", name = "retrofit2-kotlinx-serialization-converter", version.ref = "retrofitKotlinxSerializationJson" }
okhttp-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okHttp" }
okhttp-mockserver = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "okHttp" }
kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
retrofit-kotlinx-serialization = { module = "com.squareup.retrofit2:converter-kotlinx-serialization", version.ref = "retrofit" }
okhttp-logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okHttp" }
okhttp-mockwebserver = { module = "com.squareup.okhttp3:mockwebserver", version.ref = "okHttp" }
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
kotlinx-immutable-collection = { group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable", version.ref = "kotlinxImmutable" }

Expand All @@ -100,12 +98,12 @@ android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
android-test = { id = "com.android.test", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
hilt-plugin = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
baselineprofile = { id = "androidx.baselineprofile", version.ref = "baselineprofile" }

[bundles]
retrofitBundle = ["retrofit", "retrofit-kotlin-serialization", "okhttp-interceptor", "okhttp-mockserver"]
retrofitBundle = ["retrofit", "retrofit-kotlinx-serialization", "okhttp-logging-interceptor"]
Loading