kpgalligan

    kpgalligan

    3 years ago
    A question for intellij integration. For various target platforms (ios/macos, linux, androidNative), they’re all distinct with regards to “platform” and Native, but when building a library that publishes to these platforms, you’ll really want a common source set for that platform. For example, ios and macos all have “Foundation”, and they would all use it the same way. I define a source set for “apple” that each target’s source set depends on, and that builds fine, but intellij can’t resolve that. Is there a way to configure that to work as expected? I think it would be more like a hint to the IDE that didn’t really impact the compile build (something like “config as if iosArm64"). I’ve done this in the past by having a commented section in the build.gradle that gets uncommented to refresh gradle in Intellij, then commented out again, but that’s pretty ugly.
    For example…
    // macosX64(“apple”) jvm() js() macosX64() iosArm32() iosArm64() iosX64() mingwX64()
    Uncommenting the first line and refreshing intellij will get “import platform.Foundation…” to resolve in the ‘appleMain’ source set. However, expect statements with actuals in there get Intellij errors saying they’re not defined (they compile fine). This is version 2019.1 EAP (Build #IU-191.5701.16)
    russhwolf

    russhwolf

    3 years ago
    The (hacky) way I've worked around this is by picking one of those sources and making the rest of them depend on it. You'll run into https://youtrack.jetbrains.com/issue/KT-26333 which means you'll see IDE errors on your
    expect
    declarations, but it will build fine and you'll get IDE inference and autocomplete.
    kpgalligan

    kpgalligan

    3 years ago
    I was thinking that would be the way to do it. If there are open tickets I guess just hack around for now.
    russhwolf

    russhwolf

    3 years ago
    I don't know of an open ticket for what you're describing (ie inference about shared APIs between different native platforms) but I'd star it if you created one
    h

    hmole

    3 years ago
    @kpgalligan
    def emulator = "iosX64"
    def iphone = "iosArm64"
    kotlin {
      targetFromPreset(presets[emulator], "ios") {
    
      }
      targetFromPreset(presets[iphone], "iosDevice") {
    
      }
    }
    
    def compilations = kotlin.targets["iosDevice"].compilations
    afterEvaluate {
      compilations.named("main").configure { compilation ->
        compilation.source kotlin.sourceSets.findByName("iosMain")
      }
      compilations.named("test").configure { compilation ->
        compilation.source kotlin.sourceSets.findByName("iosTest")
      }
    }
    josephivie

    josephivie

    3 years ago
    Using konvenience:
    isNative.sources { 
        main {}
        test {}
    }
    ~https://github.com/lightningkite/konvenience~
    Ah, never mind. That was a misread. I see what you're asking now - unfortnately I haven't found one.
    I'm pretty sure I've seen something for this once. Some way of adding a conditional to the Gradle script that only ran when IntelliJ was analyzing the build, but that otherwise worked for builds.
    @kpgalligan I got this to work - use this:
    if (System.getProperty("idea.resolveSourceSetDependencies") != null) {
        sourceSets {
            maybeCreate("targetSpecificMain").apply {
                kotlin.srcDir("src/somePlatformsMain/kotlin")
            }
        }
    }
    This feature will be added to Konvenience by default.
    bdeg

    bdeg

    3 years ago
    If you're still looking for a solution here's my current solution:https://github.com/bitsydarel/clean-arch/blob/master/coroutines/build.gradle
    kpgalligan

    kpgalligan

    3 years ago
    Interesting. Will take a look
    bdeg

    bdeg

    3 years ago
    just check the nativeMain sourceSet