https://kotlinlang.org logo
a

addamsson

11/06/2018, 2:30 PM
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:
Copy code
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:
Copy code
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.
r

russhwolf

11/06/2018, 2:38 PM
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

11/06/2018, 2:47 PM
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? 😞
r

russhwolf

11/06/2018, 2:47 PM
Give it time. This stuff's still brand new 🙂
a

addamsson

11/06/2018, 2:57 PM
Sorry, I'm just getting a bit frustrated
💯 1
😄
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
r

russhwolf

11/06/2018, 3:02 PM
Yeah there's a lot of different pieces that can be tough to fit together
a

addamsson

11/06/2018, 3:07 PM
Do you know about anyone who has released multipkatform artifacts using the new plugin to maven central?
l

Leon Linhart

11/06/2018, 3:11 PM
Played with this just yesterday. The following snippet should get you started.
Copy code
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.
👍 1
a

addamsson

11/06/2018, 3:25 PM
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
h

h0tk3y

11/06/2018, 8:21 PM
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.
g

gaetan

11/06/2018, 9:27 PM
@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.
👍 1
a

addamsson

11/06/2018, 9:38 PM
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
g

gaetan

11/06/2018, 10:08 PM
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

11/06/2018, 10:13 PM
thanks!
i have a solution for the previous model though, I was trying to figure out the new one
👍 1