https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Shan

04/18/2019, 2:01 PM
Hey all. Should my target artifacts have a Maven dependency on Common? It's not registering when I create the Pom, not sure if that's intended or not. (I'm having issues with my project, where gradle will import the dependency fine but my project cannot find the package, which is why I ask)
h

h0tk3y

04/18/2019, 3:59 PM
That dependency is written to the POM only if you publish the library without Gradle module metadata (no
enableFeaturePreview("GRADLE_METADATA")
in
settings.gradle
), kind of legacy mode. Its absence should not affect reference resolution anyway, so there must be a different cause. Could you please provide more context or share the project if it's open-source?
s

Shan

04/18/2019, 6:57 PM
I cannot share the project as of yet unfortunately, but for context, we switched our project to a MPP and have re-published the new release versions, both a jvm and a common artifact (
org.tenkiv.coral
on maven central
<https://search.maven.org/artifact/org.tenkiv.coral/coral-jvm/2.3.2.3/jar>
). I've implemented the dependency within a different project of mine and it appears to be found correctly by gradle, but I can't import it as it says
coral
is not found.
Hmm, checking again, the POM doesn't list the dependency on my
common
code, even without using the
enableFeaturePreview("GRADLE_METADATA")
Copy code
jvm().compilations["main"].defaultSourceSet {
            dependencies {
                dependsOn(commonMain)
                implementation(kotlin("stdlib-jdk8"))
            }
        }
is this how I should be doing my reliance on commonMain within my jvm target? I will try enabling the gradle_metadata feature and see if that changes anything (for now)
Alright turns out my Jar I created in my mavenPublish configuration for my mpp was empty somehow, which I'm surprised didn't cause any problems before this.. 🙃
h

h0tk3y

04/19/2019, 11:42 AM
is this how I should be doing my reliance on commonMain within my jvm target?
It's already there by default. Each target has it's main compilation's default source set depend on
commonMain
, so adding that
dependsOn(commonMain)
line is not needed.
Can you share the part of the script that configures publishing? Do you customize the artifacts that are published?
s

Shan

04/19/2019, 3:10 PM
Thank you for the help, I'm pretty sure what my problem was was that I was creating a new publication the same way I do in my other projects (that are not MP) with
create<MavenPublication>
and trying to get the jar with
from(components["java"])
because I didn't realise MPPs generate a publication for you for each target. After adjusting it to
publications.withType<MavenPublication>().apply
and configuring my publications the same way, my Jar is now full. I'm just assuming that creating a publication and using
from(components["java"])
wasn't able to find the Jar correctly, or something to that effect, which was what was resulting in my empty jar.
👍 1
It seems to be working fine on my sonatype staging repository. Thanks again for your help!