How to configure multiplatform plugin's yarn download URL


I am migrating a project from the old kotlin platform plugin + node plugin to the kotlin multiplatform plugin (1.3.70).

The project builds a backend based on Ktor plus several web frontends using the JS target.

I am facing problems because we are behind a corporate firewall and the build fails to download the nodejs distribution and the yarn distribution.

I succeded in configuring where the plugin will download nodejs from by adding a kotlinNodeJs block to my buld:

kotlin {
    js {
        browser {
            kotlinNodeJs {
                // download = true
                // nodeVersion = "12.14.0"
                nodeDownloadBaseUrl = "<alternate download location accessible within my organisation"

Unfortunately I cant find a way to do the same for the yarn location. Looking at the kotlin-gradle-plugin source code I saw it seems to be possible (through a kotlinYarn block) to configure it but I have not been successful.

Any idea how to do that?

For anyone else who finds this, here is the incantation that works with kotlin 1.4.10 and gradle 6.6.1:

import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnPlugin
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
rootProject.plugins.withType( {
  rootProject.the<YarnRootExtension>().downloadBaseUrl = "<some internal location equivalent to the yarn/releases/download dir on github>"

For those using nodejs (not browser) there is a similar trick to tell the mpp plugin where to download nodejs:

import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
rootProject.plugins.withType( {
  rootProject.the<NodeJsRootExtension>().nodeDownloadBaseUrl = "<some internal location equivalent to the /dist dir on>"
1 Like

we have even the restriction not to use yarn… so I’d like to ask if there is an configuration to use npm instead of yarn? this would mean completely disable the use of yarn for kotlin