How to use dead code elimination in multiplatform project?

I found this: https://kotlinlang.org/docs/reference/javascript-dce.html

But trying to follow the docs there to apply the plugin fails:

plugins {
    id("kotlin-multiplatform") version "1.3.31"
    id("kotlin-dce-js")

Build file ‘/…/build.gradle.kts’ line: 18
Plugin [id: ‘kotlin-dce-js’] was not found in any of the following sources:

Where is it? If it’s already in the kotlin-multiplatform plugin, where are the tasks? Is there an example or documentation somewhere?

I see there is another plugin called kotlin frontend plugin. Maybe I should use that instead?

This question mostly about how to use Gradle Kotlin DSL
I dont use kotlin-multiplatform plugin. Just only Kotlin/JS. And this work fo me:

plugins {
    id("kotlin2js") version "1.3.31"
}

apply {
    plugin("kotlin-dce-js")
}

Add the following code to your settings.gradle:

pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "kotlin-dce-js") {
                useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
            }
        }
    }
}
1 Like

Thank you, that works. There was a similar if branch already there for "kotlin-multiplatform".

1 Like