https://kotlinlang.org logo
Title
r

rkeazor

07/01/2022, 2:02 AM
Hey how do you all, protect against Binary Compatibility issues in your libs. Let's say your working with DataClasses in a library module which is a known culprit of this . But you know that data class may grow in properties over time, what would be the best course of action to prevent binary compatibility?
t

Tijl

07/01/2022, 9:29 AM
d

Drew Hamilton

07/01/2022, 4:23 PM
I made Poko to help with this – it doesn't generate
copy
or
componentN
functions so you don't have to worry about their compatibility. You still have to keep track of constructor compatibility though, which I use the tool linked above for.
r

rkeazor

07/01/2022, 7:27 PM
but how do yall normally resolve constructor compatibility. Do youj just create secondary constructor?
d

Drew Hamilton

07/01/2022, 7:56 PM
Yeah. Alternately you could make the constructor private and write a builder.
e

ephemient

07/01/2022, 8:02 PM
if you've already exposed data classes publicly and want to maintain binary compatibility, your only options are to never change them or to convert them to non-data classes with manual additions for compatibility if you do need to change them
Kotlin's builder pattern is a bit different than Java's, for example
Json {
    coerceInputValues = true
    ignoreUnknownKeys = true
    isLenient = true
}
and not
OkHttpClient.Builder()
    .connectTimeout(1, SECONDS)
    .writeTimeout(1, SECONDS)
    .readTimeout(1, SECONDS)
    .build()
but the former is a bit less ergonomic to use from Java, if you're concerned about that
1
m

mbonnin

07/02/2022, 7:53 AM
We had data classes in an early version of our lib, we moved everything to Builders for that reason
r

rkeazor

07/02/2022, 8:45 PM
will kotlin DSL work as well @mbonnin @ephemient
m

mbonnin

07/03/2022, 11:06 AM
Not if you want java interoperability
r

rkeazor

07/04/2022, 4:45 PM
oh ok , but if its pure kotlin code , it will be fine ?
m

mbonnin

07/04/2022, 8:52 PM
Yep, for Kotlin callers it should be fine