I have an issue with kotlin project targeting js n...
# gradle
t
I have an issue with kotlin project targeting js node and browser - generateMetadataFileForKotlinMultiplatformPublication task. Details in thread.
Project configuration(simplified):
Copy code
kotlin {
    js("browser", IR) {

        compilations["main"].defaultSourceSet.dependsOn(js(IR).compilations["main"].defaultSourceSet)
        configurations[compilations["main"].apiConfigurationName].attributes.attribute(jsPlatformType, "browser")
        configurations[compilations["main"].runtimeOnlyConfigurationName].attributes.attribute(jsPlatformType, "browser")

        binaries.executable()
    }
    js("node", IR) {
        nodejs { }
        compilations["main"].defaultSourceSet.dependsOn(js(IR).compilations["main"].defaultSourceSet)
        configurations[compilations["main"].apiConfigurationName].attributes.attribute(jsPlatformType, "node")
        configurations[compilations["main"].runtimeOnlyConfigurationName].attributes.attribute(jsPlatformType, "node")
        binaries.executable()
    }
}
Error I am getting:
Copy code
Execution failed for task ':app:generateMetadataFileForKotlinMultiplatformPublication'.
> Invalid publication 'kotlinMultiplatform':
    - Variants 'browserApiElements-published' and 'jsApiElements-published' have the same attributes and capabilities. Please make sure either attributes or capabilities are different.
    - Variants 'browserRuntimeElements-published' and 'jsRuntimeElements-published' have the same attributes and capabilities. Please make sure either attributes or capabilities are different.
    - Variants 'browserApiElements-published' and 'nodeApiElements-published' have the same attributes and capabilities. Please make sure either attributes or capabilities are different.
    - Variants 'browserRuntimeElements-published' and 'nodeRuntimeElements-published' have the same attributes and capabilities. Please make sure either attributes or capabilities are different.
Any ideas on how to solve it are welcome.
When I try:
Copy code
kotlin {
    js("browser", IR) {

        compilations["main"].defaultSourceSet.dependsOn(js(IR).compilations["main"].defaultSourceSet)
        configurations.all { if(name == compilations["main"].apiConfigurationName + "Elements-published") attributes.attribute(jsPlatformType, "browser") }
        configurations.all { if(name == compilations["main"].runtimeOnlyConfigurationName + "Elements-published") attributes.attribute(jsPlatformType, "browser") }

        binaries.executable()
    }
    js("node", IR) {
        nodejs { }
        compilations["main"].defaultSourceSet.dependsOn(js(IR).compilations["main"].defaultSourceSet)
        configurations.all { if(name == compilations["main"].apiConfigurationName + "Elements-published") attributes.attribute(jsPlatformType, "node") }
        configurations.all { if(name == compilations["main"].runtimeOnlyConfigurationName + "Elements-published") attributes.attribute(jsPlatformType, "node") }
        binaries.executable()
    }
}
I am getting slightly different error:
Copy code
Execution failed for task ':app:generateMetadataFileForKotlinMultiplatformPublication'.
> Invalid publication 'kotlinMultiplatform':
    - Variants 'browserRuntimeElements-published' and 'jsRuntimeElements-published' have the same attributes and capabilities. Please make sure either attributes or capabilities are different.
    - Variants 'browserRuntimeElements-published' and 'nodeRuntimeElements-published' have the same attributes and capabilities. Please make sure either attributes or capabilities are different.
Variants 'browserRuntimeElements-published' and 'nodeRuntimeElements-published' have the same attributes and capabilities.
is now most confusing.
v
Maybe output of task
outgoingVariants
can help you shed some light on it
t
@Vampire Thanks, managed to make it work with:
Copy code
kotlin {
    js("browser", IR) {
        compilations["main"].defaultSourceSet.dependsOn(js(IR).compilations["main"].defaultSourceSet)
        configurations.all { if(name == compilations["main"].apiConfigurationName + "Elements") attributes.attribute(jsPlatformType, "browser") }
        configurations.all { if(name == "browserRuntimeElements") attributes.attribute(jsPlatformType, "browser") }
        binaries.executable()
    }
    js("node", IR) {
        nodejs { }
        compilations["main"].defaultSourceSet.dependsOn(js(IR).compilations["main"].defaultSourceSet)
        configurations.all { if(name == compilations["main"].apiConfigurationName + "Elements") attributes.attribute(jsPlatformType, "node") }
        configurations.all { if(name == "nodeRuntimeElements") attributes.attribute(jsPlatformType, "node") }
        binaries.executable()
    }
}