If I have a multiplatform child project with 2 JVM...
# multiplatform
d
If I have a multiplatform child project with 2 JVM targets, how can I select one target as a dependency in gradle?
d
implementation "com.dico:library-jvmFirst:1.0.0"
instead of just
implementation "com.dico:library-jvm:1.0.0"
or
implementation "com.dico:library:1.0.0"
.
I'm not sure if I've understood your question actually. Could you expand?
d
So I have a multiplatform project
A child project should be used as a dependency
It has 2 JVM targets
Before I had 1, I can do
api(project(":child"))
It will find the jvm target and add it as a dependency.
I tried getting the source set from the child project and using
dependsOn
in my root source set, but it seems to assume that the source set will be from the same project
d
Ah, you need to select the specific artifact but I can't find docs about it.
d
Copy code
sourceSets["jvmMain"].apply {
    val targetName = (findProperty("platform")?.toString() ?: "remote") + "Jvm"
    val target = platform.kotlin.targets[targetName]
    val jarTask = platform.tasks.getByName(target.artifactsTaskName) as Jar
    val platform = jarTask.archiveFile.get().asFile

    dependencies {
        api(engine)
        api(platform)
    }
}
Here:
Copy code
dependencies {
    api(project(":platform", "myTargetJvmApiElements")
}
d
Did that work?
d
Both of them work.
And with both of them, IntelliJ doesn't recognize the dependencies, so everything is red.
But the compile task works fine.
l
Did you report it on kotl.in/issue?
d
Actually, the
compileKotlinMetadata
doesn't work.
compileKotlinJvm
is fine
There's no "commonMainApiElements"
Does an api configuration extend an implementation configuration? @louiscad I think you might know this
Or is it the other way around? wait...
l
api is implementation + api
d
Copy code
val platform = project(":platform")
val configurationName = (findProperty("platform")?.toString() ?: "remote") + "JvmApiElements"

sourceSets["commonMain"].dependencies {
    api(engine)
    api(platform)
}

sourceSets["jvmMain"].dependencies {
    api(engine)
    api(project(":platform", configurationName))
}
works!
l
@Dico Isn't
api(engine)
a duplicate in
jvmMain
?
d
Is it? I always do it like this
l
I do it only for per platform artifacts
d
Ah it figures that part out if I put it in common. Awesome!
l
If you're using gradle metadata, yes
If the library is also compatible with gradle metadata
d
I am, I thought it just figures out which target to use from the project
but it does the same then for the other target sif its in common