https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
i

ian.shaun.thomas

12/19/2019, 2:38 PM
With a multimodule project, using a multiplatform project as a shared module and a module for web, is it not possible to use the
js
plugin in the web module? All I get is this:
Cannot add extension with name 'kotlinNodeJs', as there is an extension already registered with that name.
Library module is using
kotlin("multiplatform")
plugin and JS web module is using
kotlin("js")
. The error is triggered when trying to enable browser or nodejs as a target in the js module when browser or nodejs are enabled in the common mpp module. ie:
Copy code
js {
        browser {}
        nodejs {}
    }
I can't find examples of anyone using these together so I guess it's not possible right now?
r

russhwolf

12/19/2019, 2:43 PM
As long as the plugins are applied to different modules it should be fine. I have an example project that does this (just for broswer target) at https://github.com/russhwolf/multiplatform-hello
i

ian.shaun.thomas

12/19/2019, 2:49 PM
hmm so you are.. let me see if I can figure out what's different between our repos
looks like the difference is you define the plugins in the root build.gradle with apply false while I'm defining them all in the plugin management block of settings
Copy code
pluginManagement {
    val detekt_version: String by settings
    val kotlin_version: String by settings

    plugins {
        id("org.jetbrains.kotlin.jvm").version(kotlin_version)
        id("org.jetbrains.kotlin.js").version(kotlin_version)
        id("org.jetbrains.kotlin.multiplatform").version(kotlin_version)
        id("io.gitlab.arturbosch.detekt").version(detekt_version)
    }
}
The only reason I'm doing this is so I can define dependency versions once for tools like detekt and kotlin which also have the local deps. Thankfully kotlin plugins resolved this with the
kotlin()
helper method but tools like detekt have not. Maybe I can use a mixture of both approaches to work around this issue?
welp, using your approach got me sorted for now at least. Still annoying to have to put dependency versions in multiple places but that seems more of a gradle issue than a kotlin mpp issue so I'll take up that gripe elsewhere. Thank you 👍
r

russhwolf

12/19/2019, 3:26 PM
Yeah I've been using the apply false to avoid getting errors about specifying version for plugins that are already applied, but I don't know if there's a better way to handle that when you want to centralize versions elsewhere.
6 Views