NOTE: This is an AI generated document, reviewed and modified by human, based on the migration commit diff between v2 and v3. If you prefer concise change list, checkout the diff.
This guide helps you migrate your project from Retrosheet v1 or v2 to the new v3 version. The new version brings several major changes including switching from Retrofit to Ktorfit and from Moshi to Kotlinx Serialization.
- Replaced Retrofit with Ktorfit
- Switched from Moshi to Kotlinx Serialization
- Updated interceptor configuration to use plugins
- Changed artifact coordinates and version
Replace your old dependencies with the new ones:
// Old dependencies (v2)
plugins {
id("com.google.devtools.ksp") version "2.x.x"
kotlin("jvm") version "2.x.x"
}
dependencies {
// Moshi
implementation("com.squareup.moshi:moshi:1.x.x")
ksp("com.squareup.moshi:moshi-kotlin-codegen:1.x.x")
implementation("com.squareup.retrofit2:converter-moshi:2.x.x")
// Retrofit
implementation("com.squareup.retrofit2:retrofit:2.x.x")
// Retrosheet
implementation("com.github.theapache64:retrosheet:2.x.x")
}
// New dependencies (v3)
plugins {
id("com.google.devtools.ksp") version "2.1.20-1.0.32" // or newer
kotlin("jvm") version "2.1.20" // or newer
id("org.jetbrains.kotlin.plugin.serialization") version "2.1.20" // Add this
id("de.jensklingenberg.ktorfit") version "2.4.1" // Add this
}
dependencies {
// Kotlinx Serialization (replaces Moshi)
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0")
// Ktorfit (replaces Retrofit)
implementation("de.jensklingenberg.ktorfit:ktorfit-lib:2.4.1")
implementation("io.ktor:ktor-client-content-negotiation:3.1.1")
implementation("io.ktor:ktor-serialization-kotlinx-json:3.1.1")
// Retrosheet v3 : [latest version - i promise!]
implementation("io.github.theapache64:retrosheet:3.0.3") // Note the new artifact coordinates
// You may need SLF4J No-op implementation
implementation("org.slf4j:slf4j-nop:2.0.7")
}Replace Moshi annotations with Kotlinx Serialization annotations:
// Old (Moshi)
@JsonClass(generateAdapter = true)
data class Note(
@Json(name = "Timestamp")
val createdAt: String? = null,
@Json(name = "Title")
val title: String,
@Json(name = "Description")
val description: String
)
// New (Kotlinx Serialization)
@Serializable
data class Note(
@SerialName("Timestamp")
val createdAt: String? = null,
@SerialName("Title")
val title: String,
@SerialName("Description")
val description: String?
)Update imports and method signatures:
// Old (Retrofit)
import com.github.theapache64.retrosheet.annotations.Read
import com.github.theapache64.retrosheet.annotations.Write
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
// New (Ktorfit)
import de.jensklingenberg.ktorfit.http.Body
import de.jensklingenberg.ktorfit.http.GET
import de.jensklingenberg.ktorfit.http.POST
import io.github.theapache64.retrosheet.annotations.Read
import io.github.theapache64.retrosheet.annotations.WriteReplace the RetrosheetInterceptor with the new configuration approach:
// Old (v2)
val retrosheetInterceptor = RetrosheetInterceptor.Builder()
.setLogging(true)
// Sheet configuration
.addSheet(SHEET_NAME, "Timestamp!A:C")
// Write endpoints
.addForm(
ADD_NOTE_ENDPOINT,
SHEET_NAME,
mapOf(
"Title" to "title",
"Description" to "description"
)
)
.build()
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(retrosheetInterceptor)
.build()
val moshi = Moshi.Builder().build()
val retrofit = Retrofit.Builder()
.baseUrl("https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/")
.client(okHttpClient)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build()
return retrofit.create(NotesApi::class.java)
// New (v3)
val config = RetrosheetConfig.Builder()
.setLogging(true)
// Sheet configuration
.addSheet(SHEET_NAME, "Timestamp!A:C")
// Write endpoints
.addForm(
ADD_NOTE_ENDPOINT,
SHEET_NAME,
mapOf(
"Title" to "title",
"Description" to "description"
)
)
.build()
val ktorClient = HttpClient {
install(createRetrosheetPlugin(config)) {}
install(ContentNegotiation) {
json()
}
}
val retrofit = Ktorfit.Builder()
.baseUrl("https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/")
.httpClient(ktorClient)
.converterFactories(RetrosheetConverter(config))
.build()
return retrofit.createNotesApi() // Note the different method to create API clientTake note of the package name changes:
// Old (v2)
import com.github.theapache64.retrosheet.RetrosheetInterceptor
import com.github.theapache64.retrosheet.annotations.Read
import com.github.theapache64.retrosheet.annotations.Write
// New (v3)
import io.github.theapache64.retrosheet.annotations.Read
import io.github.theapache64.retrosheet.annotations.Write
import io.github.theapache64.retrosheet.core.RetrosheetConfig
import io.github.theapache64.retrosheet.core.RetrosheetConverter
import io.github.theapache64.retrosheet.core.createRetrosheetPlugin-
Dependency Changes:
- Switched from Retrofit to Ktorfit
- Replaced Moshi with Kotlinx Serialization
- New artifact coordinates:
io.github.theapache64:retrosheet(wascom.github.theapache64:retrosheet)
-
API Changes:
RetrosheetInterceptor→RetrosheetConfigandcreateRetrosheetPluginretrofit.create()→ktorfit.createXXX()- Package naming changes from
com.github.theapache64toio.github.theapache64
-
Serialization Changes:
@JsonClass→@Serializable@Json(name = "")→@SerialName("")
- Import Errors: Make sure to update all imports to the new package names.
- Serialization Errors: Ensure all data classes have the
@Serializableannotation and fields use@SerialName. - HTTP Client Configuration: The Ktor HTTP client configuration is significantly different from OkHttp.
- API Method Return Types: Ktorfit handles suspending functions differently; review your API interface methods.
If you encounter any issues during migration, please open an issue on the tracker.