h

    hmole

    3 years ago
    Can I depend on multiple components of a single multiplatform module from another module? I need android and jvm parts. They're separate sourcesets.
    Liliia

    Liliia

    3 years ago
    h

    hmole

    3 years ago
    For example I have mpp project with android and jvm presets. I want to depend on both of them from another android app module. If I just do implementation project(":myModule"), it only pulls the android part.
    Liliia

    Liliia

    3 years ago
    Yes, I understand, that’s why I gave you the link above. There are two ways for your case to specify the dependencies explicitly, so both will be there:
    A
    project('...')
    dependency on a multiplatform library is used. Replace it with a
    project(path: '...', configuration: '...')
    dependency. Use the appropriate target’s runtime elements configuration, such as
    jvm6RuntimeElements
    . Due to the current limitations, this dependency should be placed in a top-level dependencies { ... } block rather than in a source set’s dependencies.
    In both of the cases above, another solution is to mark the targets with a custom attribute. This, however, must be done on both the library author and the consumer sides, and it’s the library author’s responsibility to communicate the attribute and its values to the consumers;
    There is also an example of the latter case, you may take a look at how the dependency is specified for such case here: https://github.com/h0tk3y/k-new-mpp-samples/tree/master/multiple-targets-same-platform
    h

    hmole

    3 years ago
    With this setup I got imports and autocomplete from external configurations, but my buil still fails because It can't find the jvm part(
    jvmImplementation
    )
    apply plugin: 'kotlin-multiplatform'
    kotlin {
      targets {
        fromPreset(presets.android, 'android')
      }
    
      sourceSets {
        commonMain {
          dependencies {
            implementation project(":lib")
          }
        }
      }
    }
    dependencies {
      project(path: ':lib', configuration: 'jvmImplementation')
      project(path: ':lib', configuration: 'androidDebugImplementation')
    }
    Liliia

    Liliia

    3 years ago
    Now I see. What do you want to achieve by depending on two targets of the same multiplatform lib? Can you share a sample project? The problem is, those two targets may contain different realisations (
    actual
    parts) of the same class and those will obviously clash with each other. // also, it’s explicitly written in the Gradle documentation for plugins that
    implementation
    configuration isn’t consumable: https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph
    h

    hmole

    3 years ago
    One is a jar command line utility and the other is android library.They share the same model classes through common module. I want to depend on both of them to test it more easily from android app module, since both of them are jvm. So far i'm importing jvm jar directly from build folder.
    Liliia

    Liliia

    3 years ago
    Because of possible clashes and class duplications, as I mentioned above, we don’t recommend to do so and therefore there is no plan to support such configuration