Dico

    Dico

    3 years ago
    If I have a multiplatform child project with 2 JVM targets, how can I select one target as a dependency in gradle?
    Dominaezzz

    Dominaezzz

    3 years ago
    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?
    Dico

    Dico

    3 years ago
    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
    Dominaezzz

    Dominaezzz

    3 years ago
    Ah, you need to select the specific artifact but I can't find docs about it.
    Dico

    Dico

    3 years ago
    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:
    dependencies {
        api(project(":platform", "myTargetJvmApiElements")
    }
    Dominaezzz

    Dominaezzz

    3 years ago
    Did that work?
    Dico

    Dico

    3 years ago
    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.
    louiscad

    louiscad

    3 years ago
    Did you report it on kotl.in/issue?
    Dico

    Dico

    3 years ago
    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...
    louiscad

    louiscad

    3 years ago
    api is implementation + api
    Dico

    Dico

    3 years ago
    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!
    louiscad

    louiscad

    3 years ago
    @Dico Isn't
    api(engine)
    a duplicate in
    jvmMain
    ?
    Dico

    Dico

    3 years ago
    Is it? I always do it like this
    louiscad

    louiscad

    3 years ago
    I do it only for per platform artifacts
    Dico

    Dico

    3 years ago
    Ah it figures that part out if I put it in common. Awesome!
    louiscad

    louiscad

    3 years ago
    If you're using gradle metadata, yes
    If the library is also compatible with gradle metadata
    Dico

    Dico

    3 years ago
    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