a

    addamsson

    3 years ago
    Do any of you have experience setting up the
    kotlin-multiplatform
    plugin using Kotlin script (
    build.gradle.kts
    )? I have been struggling with this for quite some time now but I can't set this up properly:
    plugins {
        id("org.jetbrains.kotlin.multiplatform")
    }
    
    kotlin {
        targets {
            
        }
    }
    IDEA properly recognizes the
    kotlin
    method but there are no docs about how to set it up even with the basic example we have:
    targets {
        fromPreset(presets.jvm, 'jvm')
        fromPreset(presets.js, 'web')
    
        configure([jvm]) {
            tasks.getByName(compilations.main.compileKotlinTaskName).kotlinOptions {
                jvmTarget = '1.8'
            }
            tasks.getByName(compilations.test.compileKotlinTaskName).kotlinOptions {
                jvmTarget = '1.8'
            }
        }
    
        configure([web]) {
            tasks.getByName(compilations.main.compileKotlinTaskName).kotlinOptions {
                sourceMap = true
            }
        }
    }
    there is no
    fromPreset
    method for example defined on
    KotlinTarget
    so I'm a bit puzzled.
    russhwolf

    russhwolf

    3 years ago
    The Kotlin DSL is not supported yet. See note in the docs here: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html
    a

    addamsson

    3 years ago
    Don't you think it is kind of depressing that you can use the
    kotlin-dsl
    for zounds of projects but not for Kotlin-related projects? 😞
    russhwolf

    russhwolf

    3 years ago
    Give it time. This stuff's still brand new 🙂
    a

    addamsson

    3 years ago
    Sorry, I'm just getting a bit frustrated
    😄
    I'm trying to publish my project on Maven Central but it needs sources and javadoc
    but it is not set up for multiplatform projects so I'm tyring to figure out how to use it properly
    and it drives me nuts
    russhwolf

    russhwolf

    3 years ago
    Yeah there's a lot of different pieces that can be tough to fit together
    a

    addamsson

    3 years ago
    Do you know about anyone who has released multipkatform artifacts using the new plugin to maven central?
    Leon Linhart

    Leon Linhart

    3 years ago
    Played with this just yesterday. The following snippet should get you started.
    import org.jetbrains.kotlin.gradle.dsl.*
    import org.jetbrains.kotlin.gradle.plugin.*
    
    plugins {
        kotlin("multiplatform") version "1.3.0"
    }
    
    kotlin {
        experimental.coroutines = Coroutines.ENABLE
    
        targets {
            fromPreset(presets.getByName("js"), "js")
            fromPreset(presets.getByName("jvm"), "jvm")
        }
    
        sourceSets {
            configureEach {
                languageSettings.apply {
                    languageVersion = "1.3"
                    apiVersion = "1.3"
    
                    useExperimentalAnnotation("kotlin.Experimental")
                }
            }
    
            getByName("commonMain").dependencies {
                // ...
            }
    
            getByName("jsMain").dependencies {
                // ...
            }
    
            getByName("jsTest").dependencies {
                // ...
            }
    
            getByName("jvmMain").dependencies {
                // ...
            }
    
            getByName("jvmTest").dependencies {
                // ...
            }
        }
    }
    
    fun <T : KotlinTarget> NamedDomainObjectCollection<KotlinTarget>.fromPreset(preset: KotlinTargetPreset<T>, name: String, configureAction: T.() -> Unit = {}): T {
        val target = preset.createTarget(name)
        add(target)
        target.run(configureAction)
        return target
    }
    While using the new MPP plugin with Kotlin DSL is still unsupported it seems to work perfectly fine. Just a little bit inconvenient atm.
    a

    addamsson

    3 years ago
    yep I missed the
    getByName
    part
    I think I'll just drop Maven Central for a while and use bintray instead
    I've wasted enough time already
    h0tk3y

    h0tk3y

    3 years ago
    The support for the Kotlin DSL in the form of additional extensions is going to be provided in the upcoming updates. We decided to postpone it because the whole model of multiplatform projects may change, and Kotlin script are more vulnerable to API changes (compared to Groovy, there's more imports and type names). Additionally, providing a convenient Kotlin DSL, compared to Groovy, requires a type-safe hierarchy which just needs an additional bit of work over what we already had for Groovy.
    gaetan

    gaetan

    3 years ago
    @addamsson It’s what we’ve done. Upload to bintray and then sync on maven from bintray. But I understand you, it’s currently very frustrating because it takes so much time to make all working.
    a

    addamsson

    3 years ago
    Do you have a working setup for bintray?
    I'Il try that one
    I'm not sure it will be much easier this way since I still need to add the sources and the javadoc jar
    on the screenshot it states that I need to comply with Maven Central requirements
    gaetan

    gaetan

    3 years ago
    I tried the new MPP but gave up because of the lack of documentation. So my gradle script are working but with the previous model. https://github.com/data2viz/data2viz
    Under the gradle directory you will find some specific files for publishing.
    a

    addamsson

    3 years ago
    thanks!
    i have a solution for the previous model though, I was trying to figure out the new one