I’ve just found out that during the `:kotlin-compi...
# compiler
i
I’ve just found out that during the
:kotlin-compiler-embeddable
build some packages are being relocated.
kotlinx.collections.immutable
is being relocated as well. This leads to a string constants inside
kotlin-parcelize
plugin being rewritten this way:
Copy code
kotlinx.collections.immutable.PersistentList -> org.jetbrains.kotlin.kotlinx.collections.immutable.PersistentList
This rewrite breaks my
kotlinx-parcelize
changes, since I need package names to match target project package names. Is there a non-hacky way to exclude kotlinx-parcelize from package relocation process?
d
It's very strange Build of
embeddable
jars doesn't touch string constants, only FQNs of classes in
.class
files So you can't, for example, directly depend on
kotlinx-serialization
in plugin and compare smth using FQNs from reflection (because on runtime of plugin classes will be renamed), but you perfectly can use some string constants Check how it's done in Lombok plugin for example
i
Are you sure? I’ve just made
./gradlew publishToMavenLocal
and inspected the
BuiltinParcelableTypes.class
Here’s rewritten constants 🙂 I can see the same ones during debug of kotlin compiler in the target project. On the second screenshot you can see sources of this class
I think in can touch string constants at least for the purposes of not breaking reflective access to classes with rewritten packages
Yeah, I’ve just checked. I’ve removed
kotlinx.collections.immutable
from
packagesToRelocate
list inside
embeddable.kt
and now constants look exactly as they should be.
d
Unfortunately, it is not acceptable solution (in case if you want to create MR for your changes) I'll discuss it with a team
i
Sure, I understand that it’s not acceptable, I’ve just checked 😃
I will check the
ShadowJar
docs to find if I can exclude some owning packages from relocation
d
I invented a potential workaround:
Copy code
val PARCELABLE_CONTAINER_FQNAMES = setOf(
        ...,
        kotlinxImmutable("PersistentList")
    )

    private fun kotlinxImmutable(name: String): String {
        return listOf("kotlinx", "collections", "immutable", name).joinToString(".")
    }
In this case there won't be any
kotlinx.collections.immutable
literal in the bytecode
i
Yeah, I’ve thought about this one, but it’s a bit hacky. Is it acceptable?
d
Yeah, sure Just add the commentary, why it is required
i
Ok, thanks 😃