addamsson
11/06/2018, 2:30 PMkotlin-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
11/06/2018, 2:38 PMaddamsson
11/06/2018, 2:47 PMkotlin-dsl
for zounds of projects but not for Kotlin-related projects? 😞russhwolf
11/06/2018, 2:47 PMaddamsson
11/06/2018, 2:57 PMkts
files: https://github.com/gradle-guides/building-kotlin-jvm-libraries/blob/master/samples/code/my-kotlin-library/build.gradle.ktsrusshwolf
11/06/2018, 3:02 PMaddamsson
11/06/2018, 3:07 PMLeon Linhart
11/06/2018, 3:11 PMimport 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.addamsson
11/06/2018, 3:25 PMgetByName
parth0tk3y
11/06/2018, 8:21 PMgaetan
11/06/2018, 9:27 PMaddamsson
11/06/2018, 9:38 PMgaetan
11/06/2018, 10:08 PMaddamsson
11/06/2018, 10:13 PM