With 2.1.0-RC, I’m getting this warning in my root...
# eap
c
With 2.1.0-RC, I’m getting this warning in my root build.gradle.kts where I configure
NodeJsRootExtension
.
Copy code
'download: Boolean' is deprecated. Use download from NodeJsExtension (not NodeJsRootExtension) insteadYou can find this extension after applying NodeJsPlugin. This will be removed in 2.2
What’s the actual Gradle plugin ID for
NodeJsPlugin
?
youtrack 1
1
a
h
Nope, the plugin has no id, you have to apply the class in the rootproject.
But it should be applied by the MPP plugin automatically, so just use the renamed extension.
c
I’m not currently applying the kmp plugin in my root build.gradle.kts, is that necessary now?
h
No, you just need to rename the extension usage.
c
Ok, I think I got it. Finding
NodeJsEnvSpec
wasn’t easy.
t
cc @Ilya Goncharov [JB]
c
No, I don’t have it working quite right yet. I’m trying to make installation of node configurable, the version of node configurable, and blocking adding of repositories by gradle plugins. I had this working in prior versions of Kotlin. With Kotlin 2.1-RC, this is what I’m trying
Copy code
rootProject.plugins.withType<NodeJsPlugin> {
    kotlinNodeJsEnvSpec.apply {
        download = project.property("SIGMA_IS_INSTALL_NODE").toString().toBoolean()
        version = libs.versions.node.get()

        // The repository is configured in the root settings.gradle.kts, and this disables Kotlin Gradle plugin from adding it
        downloadBaseUrl = null
    }
}
When the gradle build runs, I see
Build was configured to prefer settings repositories over project repositories but repository 'Distributions at <https://nodejs.org/dist>' was added by unknown code
i
Now you can configure all node js settings for all projects. So to disable you need to disable it for all projects instead of just for
rootProject
The easiest way is to use block
allprojects {}
c
I thought
allproject {}
was generally frowned upon generally for Gradle? Can I do this with a convention plugin now? I have a js convention that I apply to all submodules that use Kotlin JS
i
Yes, you can do this with just convention plugin. You just need to "find" plugin on just
project
instead of
rootProject
c
Ok, let me give that a try. Thanks!
OK so I tried doing kotlin-js-conventions.gradle.kts
Copy code
plugins.withType<NodeJsPlugin> {
    kotlinNodeJsEnvSpec.apply {
        download = project.property("IS_INSTALL_NODE").toString().toBoolean()
        version = versionCatalogs
            .named("libs")
            .findVersion("node")
            .get()
            .toString()


        // The repository is configured in the root settings.gradle.kts, and this disables Kotlin Gradle plugin from adding it
        downloadBaseUrl = null
    }
}
I also tried root build.gradle.kts
Copy code
allprojects {
    plugins.withType<NodeJsPlugin> {
        kotlinNodeJsEnvSpec.apply {
            download = project.property("IS_INSTALL_NODE").toString().toBoolean()
            version = libs.versions.node.get()

            // The repository is configured in the root settings.gradle.kts, and this disables Kotlin Gradle plugin from adding it
            downloadBaseUrl = null
        }
    }
}
In both cases, I see the build logs emitting
Build was configured to prefer settings repositories over project repositories but repository 'Distributions at <https://nodejs.org/dist>' was added by unknown code
So it seems like it isn’t having the intended effect.
i
Yes, looks like a bug indeed. We use
convention
for default value of
downloadBaseUrl
, that’s why
null
is ignored.
h
As a workaround use
set(provider { null })
a
KT-72874 cc @Ilya Goncharov [JB]
c
Philip’s suggested workaround of
set(provider { null })
does not work for me
h
I use this code to disable the repo:
Copy code
plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsPlugin> {
    (extensions.getByName(NodeJsEnvSpec.EXTENSION_NAME) as NodeJsEnvSpec).downloadBaseUrl.set(null as String?)
}
c
OK, I think I got some progress on this. I needed both a convention plugin applied to my submodules, plus a declaration in my top-level build.gradle.kts with configuration on the root project.
s
Yes, you can do this with just convention plugin. You just need to “find” plugin on just
project
instead of
rootProject
@Ilya Goncharov [JB] is this the case for Npm plugin also? I just tried to configure
NpmExtension
for overriding the
lockFileDirectory
and seems like it will only work if i apply on rootProject.
i
NPM plugin is still applied only on root project, because NPM project is setup in
<rootProject>/build/js
, so it is still not clear how we can isolate it in one project
🆗 1