https://kotlinlang.org logo
Join SlackCommunities
Powered by
# library-development
  • e

    eygraber

    07/16/2024, 5:51 PM
    Anyone have thoughts on Maven Central Portal not allowing SNAPSHOTS? I'm not a fan, and I use SNAPSHOTS specifically for the reason they call out for SNAPSHOTS being "bad" 😆
    it has the side effect of users being able to make their pre-release versions available to their communities during ongoing development
    I feel like that's a very valuable tool, since it makes it very easy for the community to verify that something works, or adopt changes before a release is made. It's probably not the best solution for this, and a full release pipeline would probably be "better", but I think that's unfeasible for small projects that don't have the manpower to setup and manage those types of solutions.
    ➕ 3
    e
    m
    +2
    • 5
    • 51
  • s

    Slackbot

    07/19/2024, 5:55 PM
    This message was deleted.
    not kotlin but kotlin colored 1
    e
    • 2
    • 1
  • a

    arnaud.giuliani

    07/24/2024, 7:13 AM
    Hello 👋 I'm a bit lost with all JVM option that we can setup in a kotlin library. #Koin is working with Java 8 sources/target compat. I don't see any need to change it, apart following Android ecosystem AGP. Do you see any strong advise to not stay in Java 8 sources/taget compat?
    m
    j
    e
    • 4
    • 33
  • m

    mbonnin

    07/25/2024, 3:48 PM
    The Google Play SDK Index requires to put a small file in the
    META-INF
    folder of the jar for verification purposes (doc). While it’s probably technically OK (the file is small), it still feels a bit weird. It’s adding noise to the binary for no apparent good reason. The file could be put in another artifact or sounds like we could use GPG signatures for that. Any thoughts about this? Is that common practice?
    👀 1
    c
    e
    • 3
    • 7
  • s

    Sebastian Sellmair [JB]

    08/09/2024, 7:37 PM
    Hey Folks 👋 Not sure if this is the correct channel, but I am desperately looking for feedback on how to improve the README.md of my library here: https://github.com/sellmair/evas
    e
    m
    c
    • 4
    • 5
  • e

    Emil Kantis

    08/19/2024, 7:00 AM
    Seems Github takes forever (days w/o resolving) to allocate macos runners for testing my lib on iOS, macOS (etc.) targets. Anyone else having the same issue?
    ✅ 1
    b
    • 2
    • 3
  • l

    Loïc Lamarque

    09/18/2024, 9:21 AM
    Attention Kotlin Library Authors! 🚀 We’re working on Kotools Samples, a Gradle plugin that will simplify your documentation process by inlining read-only Kotlin and Java code samples into Dokka. No more editable or outdated code examples — everything is compiled alongside your main sources and visible directly in the IDE! 😍 Star and watch our GitHub repo to stay updated on the first release! ⭐ Join us in the #C05H0L1LD25 channel, and be among the first to level up your library docs! 📚✨
    ⭐ 2
  • o

    Oleg Yukhnevich

    10/03/2024, 10:23 AM
    Dokka 2.0.0-Beta has been released with Dokka's Gradle plugin v2 based on Dokkatoo! Please check the migration guide for the update procedure, we would really appreciate your feedback! kodee loving More info can be found in #dokka!
    🔥 1
  • a

    Alex Styl

    10/18/2024, 3:35 AM
    what is your go-to publish library flow? I currently build the library and release to maven from my macbook but im getting tired of waiting for it to finish, so i have started considering automating it. Maybe have github actions start the publishing process after I create release on github? Might be confusing for people to see the github release but the actual thing not being available yet
    e
    j
    • 3
    • 7
  • p

    Piotr Krzemiński

    10/18/2024, 6:45 AM
    We're facing an interesting challenge when it comes to the visibility of
    copy
    and the change related to it that is going to be made in Kotlin 2.1.0 (ref). We do have some thoughts, but I wanted to consult it with wider group of people before we decide on something. In the library github-workflows-kt, we generate certain data classes on the server side, and the users consume them via Kotlin Scripting. Here's a simple example of such generated class: SimpleActionWithRequiredStringInputs.kt. Notice what is done with the constructors: there are two, and the primary constructor is made private. It's because we want to enforce using named arguments when instantiating the class. To achieve it, we use a kind of hack with
    vararg pleaseUseNamedArguments: Unit
    as the first arg, and it's done in the secondary constructor because
    Primary constructor vararg parameters are prohibited for data classes.
    - that's why we also make the primary one private. Now, the whole problem revolves around the fact that our users may already depend on the existence of the public
    copy
    method. It's going to become private starting Kotlin 2.1.0. We want to keep providing this API for the users. These ideas came to our minds, among others: 1. implement
    copy
    ourselves ◦ won't work since there would be conflicting overloads 2. ensure that named arguments are used in a different way, e.g. in runtime via reflection (performance-wise, it's OK), then we could make the primary constructor public ◦ is it even possible? named/positional arguments distinction exists probably only in compile time 3. make the classes regular (non-
    data
    ) and implement everything that data classes provide on our own, with the ultimate control over visibility ◦ well, it would probably work, but it's complex and I'm trying to see if there's another way 😄 So basically, the problem boils down to this: data classes (or data-like classes) with enforcing named arguments upon creation, working in Kotlin 2.1.0+. Our discussion so far: https://kotlinlang.slack.com/archives/C02UUATR7RC/p1724584851609139 Any novel take on this problem is greatly appreciated! CC @Vampire
    e
    v
    • 3
    • 16
  • m

    Matthew Feinberg

    10/21/2024, 4:39 AM
    [RESOLVED] I have a situation where the Desktop version of an
    expect fun
    (part of our library implementation) is being called on Android builds, but only when our library is included as a dependency (in the "sample" app, it works fine)! I have no idea where to start to try to diagnose this problem. Any pointers would be greatly appreciated. If it matters, the function in question is a composable function:
    Copy code
    @Composable
    internal expect fun PlatformRenderView(...)
    Background: We're building a multiplatform declarative video compositing library that uses OpenGL and Metal under the hood, so we need expect/actual composable views for rendering. We release the library internally for now in our private GitHub Gradle Registry, but plan to open-source it in the future when we're happy with it's level of polish. It includes targets for Desktop, Android, and iOS. We have a "sample" folder alongside the "lib" folder (in
    settings.gradle.kts
    we have
    include(":sample:composeApp")
    and
    include(":lib")
    ). When running the sample app, everything works fine on both Desktop and Android targets. However, when we publish the
    lib
    internally (using
    maven-publish
    ) and try to use it as a dependency in another multiplatform project, the Desktop build works fine, but whenever we try to call a
    expect
    function on the Android built, it tries to use the desktop
    actual
    rather than the Android
    actual
    .
    I'm guessing this is some kind of gradle configuration issue, but I'm not deeply experienced with gradle and have no idea where to start. Can anyone help point me in the right direction?
    e
    • 2
    • 4
  • s

    Shreyash Kore

    10/25/2024, 9:05 AM
    Hi guys! I need guidance on how to deploy SNAPSHOT builds now that OSS doesn't allow creating new accounts? I have my account on Central and was created relatively recently. I want to publish SNAPSHOT versions of my project . The only way I could find is to contact Maven to get my lib published at OSS. I would appreciate any help.
    m
    t
    +2
    • 5
    • 23
  • c

    CLOVIS

    10/30/2024, 8:59 PM
    I have many classes that are "configuration classes". Ideally, each field of these classes would be a default parameter, but adding a new one would be a breaking change, so they're in classes instead. For example;
    Copy code
    myLib.foo(FooOptions { … })
    myLib.bar(BarOptions { … })
    I also have many options that are common between multiple types. What's the best way to avoid duplicating all common options between all types? So far, my best candidate is:
    Copy code
    interface CommonOptions {
        fun option1(…)
        fun option2(…)
    }
    
    class FooOptions : CommonOptions {
        private var option1 …
        private var option2 …
        private var option3 …
    
        override fun option1(…) { option1 = … }
        override fun option2(…) { option2 = … }
        fun option3(…) { option3 = … }
    }
    
    class BarOptions : CommonOptions {
        private var option1 …
        private var option2 …
        private var option4 …
    
        override fun option1(…) { option1 = … }
        override fun option2(…) { option2 = … }
        fun option4(…) { option4 = … }
    }
    and, sure, it works, but it's very verbose :/
    👀 2
    m
    • 2
    • 6
  • s

    Soren Roth

    11/01/2024, 6:52 PM
    Is there any way to have an api member that is public but also not discoverable by a client? i.e. if you know it is there, you can use it, otherwise it is invisible? I think the answer is no, but I need to confirm.
    j
    b
    • 3
    • 9
  • z

    Zach Klippenstein (he/him) [MOD]

    11/01/2024, 8:49 PM
    No idea where to post this, but has anyone built a Kotlin compiler plugin that just gives you macro-like things to inject the current filename and line number? Solved: https://github.com/JakeWharton/cite
  • m

    mika

    11/04/2024, 9:16 AM
    Hi, I’d like to suggest adding time complexity information for functions in Kotlin, especially in the Standard Library. Swift provides a great example of this—functions like
    Array.contains(_:)
    come with documented complexity, which I find very useful. I really miss having something similar in Kotlin. Here’s why I believe it would be valuable: 1. It enhances the development experience. 2. It promotes better, more efficient code. 3. It serves as a helpful form of documentation. 4. It centralizes the work, saving every developer from having to research complexities individually. One possible approach could be to automate the calculation of time complexity empirically, using performance measurements across different
    n
    values and object types (based on platform and common use cases). Please let me know what you think—I’d be happy to assist with this. Best regards, Mika
    j
    • 2
    • 7
  • m

    Mikael Ståldal

    11/12/2024, 8:42 AM
    I need a tool to check if I break binary compatibility in my library. I stumbled across binary-compatibility-validator, and it looks promising. However, it seems like it depends on Gradle, and I use Maven as my build system. Is it possible to use from Maven (possibly with Maven exec if there is not proper Maven plugin)? Or is there some other similar tool which works from Maven?
    e
    a
    +2
    • 5
    • 18
  • d

    dominicmarmion

    12/04/2024, 12:44 PM
    Hi, I am researching KMP as an option to implement shared business logic code within our existing android and iOS sdk. Is my understanding of using KMP for shared code accurate?..... 🧵
    c
    • 2
    • 8
  • w

    wakingrufus

    12/08/2024, 6:49 PM
    Is there any public info on kotlin version adoption/usage? Trying to decide about a reasonable kotlin version range to support
    👀 1
    m
    e
    • 3
    • 4
  • c

    CLOVIS

    12/11/2024, 2:28 PM
    Which version of the JDK are you all targeting? For now, I was targeting 17, but I'm getting complaints that Android is stuck on 11? Is there a consensus in the community?
    m
    a
    +2
    • 5
    • 6
  • d

    Dan Rusu

    12/18/2024, 7:08 PM
    Should we avoid
    @UnsafeVariance
    ? I'm trying to decide the best approach for the Immutable Arrays library. Immutable Arrays are covariant so you can pass an
    ImmutableArray<Employee>
    to functions that expect
    ImmutableArray<Person>
    when
    Employee
    extends
    Person
    . With
    ImmutableArray<T>
    , most operations produce
    T
    but there are a handful that consume `T`: •
    contains(element: T)
    •
    indexOf(element: T)
    •
    lastIndexOf(element: T)
    •
    getOrElse(index: Int, default: (Int) -> T)
    There are also a couple that might be more dangerous for ensuring type safety if
    T
    was declared as `in T`: •
    plus(element: T)
    // creates a new Immutable Array with the element appended •
    plus(elements: ImmutableArray<T>)
    // creates a new Immutable Array with the elements appended Attempting to add any of these methods results in an error:
    Type parameter 'T' is declared as 'out' but occurs in 'in' position
    I worked around this problem by turning these methods into extension functions which utilize allowed methods:
    Copy code
    fun <T> ImmutableArray<T>.contains(element: T): Boolean {
        return any { it == element }
    }
    
    fun <T> ImmutableArray<T>.indexOf(element: T): Int {
        forEachIndexed { index, value -> if (value == element) return index }
        return -1
    }
    //...
    The extension functions require additional imports (which IntelliJ nicely auto-suggests) so I'm wondering whether to continue with the extension function approach for these handful of operations or whether to make them regular methods by using
    @UnsafeVariance
    to avoid the imports. Searching in YouTrack, I get the impression that Kotlin is moving away from using
    @UnsafeVariance
    but I'm not sure if I'm interpreting that correctly: • https://youtrack.jetbrains.com/issue/KT-57603/Prohibit-using-UnsafeVariance-for-invariant-type-parameter • https://youtrack.jetbrains.com/issue/KTLC-72/K2-Stop-relying-on-the-presence-of-UnsafeVariance-using-for-contravariant-parameters I noticed that kotlinx immutable collections use
    @UnsafeVariance
    for their persistent abilities. Does anyone know the official direction that the Kotlin team is planning for
    @UnsafeVariance
    or what the officially recommended approach is for dealing with these types of variance scenarios?
    👀 1
    d
    • 2
    • 1
  • m

    Marcin Mycek

    12/20/2024, 9:10 AM
    K Hey Library Authors! 🎅🏻 🎁 Starting with Kotlin 2.1.0 you can publish Kotlin libraries from any host*! What this means in practice is that you don't need a Mac machine to publish a KMP library targeting all platforms (including iOS, MacOS, and WatchOS). For example if you are using GitHub CI/CD you can use the cheaper non-Mac hosts and still target Mac platforms (or add support for Mac platforms if you didn't before). The feature is still experimental and you need to opt-in:
    Copy code
    # gradle.properties
    kotlin.native.enableKlibsCrossCompilation=true
    We are looking for any unknown limitations and problems we need to address. We would appreciate your feedback if you encounter any in this YouTrack issue! *Cross-compilation has some limitations. You still need to use a Mac machine if: • Your library has a cinterop dependency. • You have CocoaPods integration set up in your project. • You need to build or test final binaries for Apple targets. For cinterop dependencies we are tracking this in this YouTrack issue and would love to hear what's your use case there!
    very nice 8
    🆒 1
    🚀 9
    👍 1
    K 20
    K 2
    ❤️ 3
    m
    • 2
    • 1
  • s

    Soren Roth

    01/13/2025, 11:49 PM
    What is the best practice to publish objective c or swift code within a KMP library? It is all internal code, but necessary to make the API work. I've got it in a cocoapod that is pulled in from the local filesystem, I am realizing it won't get packaged into my publication!
    m
    d
    +2
    • 5
    • 15
  • a

    arnaud.giuliani

    02/18/2025, 4:02 PM
    Should all KMP libraries target all available Kotlin platforms? For example, a KMP library for mobile apps (Android/iOS). Is it ok to have only Android/iOS* platform targets? Or do you expect to have other targets available but just a message saying the library doesn't support it?
    j
    j
    m
    • 4
    • 9
  • i

    Ivan Carracedo Asensio

    02/26/2025, 11:38 AM
    Hi, can someone help with this?: https://kotlinlang.slack.com/archives/C19FD9681/p1740569844948529
    ➕ 1
  • c

    CLOVIS

    03/06/2025, 3:55 PM
    Let's say I have two interfaces
    Copy code
    interface FooA {
        fun foo(name: String, value: Int)
    }
    
    interface FooB {
        fun foo(value: Int)
    }
    The two interfaces represent two different ways of interacting with a single entity. In some contexts, the library provides an instance of the first interface, and in some contexts, the library provides an instance of the second interface. However, since they are both used to interact with a single entity, it's more convenient for the library author to implement a single instance that can be viewed as both:
    Copy code
    private class FooImpl : FooA, FooB {
        override fun foo(name: String, value: Int) {}
        override fun foo(value: Int) {}
    }
    So far, everything is good I think. I think however there is a risk that a user would use a cast to change their access context even if it's not allowed.
    Copy code
    withFooA {      // provided by the library
        it as FooB  // will succeed because FooImpl does implement FooB
        it.foo(4)   // illegal call to FooB.foo in the context of FooA, but will compile and run
    }
    Should this be considered a risk? Should I split the implementations of the two interfaces to stop this usage? Or should I consider that this is bad code anyway and I should ignore the fact that users could write it?
    e
    j
    • 3
    • 6
  • c

    Cosmin Mihu

    03/09/2025, 5:34 AM
    👋 I have a kmp lib that is a tool for developers. Because of that, there should be 2 variants of the library. One for debug (the library code is fully integrated into developer artifact - apk, jar, ...) and one for release (the library code that is integrated into developer artifact has only the public code with empty bodies). How would you design this in order to avoid to switch between 2 variants each time when the developer needs a new artifact? Unfortunatly, in kmp we do not have debugImplementation and releaseImplementation.
    c
    • 2
    • 2
  • c

    CLOVIS

    03/21/2025, 9:15 PM
    What is the number of overloads to a single function that is simply too many? I have a case where I would need ~600 overloads for a single function, and that sounds like a bad idea.
    😆 7
    j
    a
    +4
    • 7
    • 12
  • t

    Tomer

    04/04/2025, 2:10 PM
    Hey folks, question about
    @UnsafeVariance
    . If I am defining some
    Container<out T>
    class and I want one of its methods to return
    Optional<T>
    (for Java users), then is it safe/reasonable to do
    Optional<@UnsafeVariance T>
    ? I don't want to do
    Optional<out T>
    since that will end up being
    Optional<? extends T>
    for Java users, which is annoying to work with. I think using
    @UnsafeVariance
    here makes sense because
    Optional
    is an immutable container so you can only get
    T
    out of it; you can't put a new
    T
    into an existing
    Optional<T>
    . It's just that Java obviously does not define
    Optional
    with
    out T
    at it's declaration (since it's not Kotlin) Am I making sense? Am I missing anything here?
    👀 1
    d
    • 2
    • 11
  • f

    Fudge

    04/21/2025, 5:34 PM
    Guys, how do you use
    @Sample
    ? Usually samples are not part of the main source set, so doesn't that mean samples will always not resolve?
    f
    v
    • 3
    • 3