I recall there was a way to change the Yarn versio...
# javascript
e
I recall there was a way to change the Yarn version, but can't seem to find it anymore, at least not using the deprecated
version
property. How do I access
YarnRootEnvSpec
in 2.2.21?
Copy code
An exception occurred applying plugin request [id: 'project.module']
> Failed to apply plugin 'project.module'.
   > Extension of type 'YarnRootEnvSpec' does not exist. Currently registered extension types: [ExtraPropertiesExtension, LibrariesForLibs, VersionCatalogsExtension, RootProjectAccessor, KotlinMultiplatformExtension, KotlinTestsRegistry, BasePluginExtension, DefaultArtifactPublicationSet, SourceSetContainer, ReportingExtension, JavaToolchainService, JavaPluginExtension, KotlinArtifactsExtensionImpl, PublishingExtension, ProjectModuleExtension]
In the context of my
buildSrc
plugin:
Copy code
class ProjectModulePlugin : Plugin<Project> {
  override fun apply(project: Project) {
    project.apply<KotlinMultiplatformPluginWrapper>()
    project.apply<MavenPublishPlugin>()

    // Register an extension to allow configuring the plugin using
    //
    // projectModule {
    //   ...
    // }
    project.extensions.create<ProjectModuleExtension>("projectModule", project)

    // Configure the Yarn environment for all K/JS modules
    project.plugins.withType<YarnPlugin> {
      project.the<YarnRootEnvSpec>().apply {
        version.set("1.22.22")

        // See https://youtrack.jetbrains.com/issue/KT-52578
        ignoreScripts.set(false)
      }
    }
    // ...
Nope that doesn't work.
YarnPlugin
instances don't seem to exist.
a
CC: @Adam Semenenko @Ilya Goncharov [JB]
e
@Artem Kobzar I think it is my fault. I recall the problem is the Yarn and Node configuration is now only applicable to the root project. My plugin, which in turn configured them, is applied on every single module.
I moved this piece of code to the root `build.gradle.kts`:
Copy code
// Configure Node.js
plugins.withTypeNodeJsPlugin {
  theNodeJsEnvSpec().apply {
    // The Node.js version must always come from the root project configuration
    version = project.stringProperty("project.node.version")
  }
}

// Configure Yarn Classic
plugins.withTypeYarnPlugin {
  theYarnRootEnvSpec().apply {
    // Use the latest version of Yarn Classic
    version = "1.22.22"

    // See https://youtrack.jetbrains.com/issue/KT-52578
    ignoreScripts = false
  }
}
And on the next Gradle command I saw:
Copy code
18:15:18: Executing 'clean assemble --no-build-cache --no-configuration-cache'…

Type-safe project accessors is an incubating feature.
> Task :buildSrc:checkKotlinGradlePluginConfigurationErrors SKIPPED
> Task :buildSrc:compileKotlin UP-TO-DATE
> Task :buildSrc:compileJava NO-SOURCE
> Task :buildSrc:compileGroovy NO-SOURCE
> Task :buildSrc:pluginDescriptors UP-TO-DATE
> Task :buildSrc:processResources UP-TO-DATE
> Task :buildSrc:classes UP-TO-DATE
> Task :buildSrc:jar UP-TO-DATE

> Configure project :faproto
Node version 20.9.0
Yarn version 1.22.22
Download https://github.com/yarnpkg/yarn/releases/download/v1.22.22/yarn-v1.22.22.tar.gz, took 473 ms
So I think it is being applied correctly now. But confirmation would be cool!
Yeah the issue is most likely:
Copy code
project.plugins.withTypeYarnPlugin
It should have been:
Copy code
rootProject.plugins.withTypeYarnPlugin
👌 1
a
eventually I hope to re-implement the tool management code to make it easier to understand and use. 'Custom tool installation management' is needed for JS, Wasm and Native.
gratitude thank you 1