I need to publish a single fat jar built from Kotlin MPP project which consists of several sub-projects.
This fat jar is to be consumed in Kotlin jvm or just plain java project.
I’ve tried to build fat jar with gradle task like this:
In both cases the resulting jar look just fine to me - I can see all class files in there.
But when added to a kotlin.jvm project as a library IDEA refuses to resolve classes and packages in this library starting from the topmost package.
Gradle build fails differently - it complains that some static members are private when they are public in the source code.
At the same time if I publish multiple jars (per every subproject) then I can consume them in another kotlin.jvm gradle project just fine (IDEA wouldn’t connect sources but this is minor issue).
Apparently fat jar I’m building lacking something or is corrupted in some other way.
Some details on the errors would be very helpful. What I strongly suspect is that you are hitting a problem with attributes. MPP uses gradle attributes to distinguish between different platform targets. These attributes apply to configurations (and thus also artifacts), but hand-written ones may not have these attributes.
In parallel, when consuming such multi-target artifacts/projects, the consumer must also use attributes. One so that resolution knows the attribute values that apply to the project, but also to specify resolution when there is no full match (or missing value). MPP does this automatically for you, I’m not sure that the Kotlin plugin now does this, but non-kotlin projects will certainly not do this and you have to do it by hand.
I have some sample plugin code for a buildSrc plugin that does this in my project:
@alshan please, check if your fat-jar contains .kotlin_metadata files. If it does, then it’s a https://youtrack.jetbrains.com/issue/KT-25709, and the simple workaround is to exclude .kotlin_metadata-files from the fat-jar