node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
601 stars 117 forks source link

Unable to specify registry for yarnSetup task #253

Closed lhhong closed 1 year ago

lhhong commented 1 year ago

So I tried this https://github.com/node-gradle/gradle-node-plugin/blob/master/docs/faq.md#how-do-i-specify-a-registry-for-the-npm-setup-task but changing npmSetup to yarnSetup but was hit with "property 'args' is final and cannot be changed any further."

Looks like the YarnSetupTask did not allow overriding of args: https://github.com/node-gradle/gradle-node-plugin/blob/4eda1f3952e8539252941e113eb32cfbca31298e/src/main/kotlin/com/github/gradle/node/yarn/task/YarnSetupTask.kt making this not possible. The only workaround right now is to include .npmrc in the npm working directory but is not ideal because we cannot then bundle the registry with repository. It becomes a manual step for the developer.

deepy commented 1 year ago

This is unfortunately a flaw in the documentation (see https://github.com/node-gradle/gradle-node-plugin/issues/208) args is a Property and while you cannot re-assign it, you can query and change the value of the property (see Lazy Configuration for more information)

Dropping the doFirst {} should make this work again, I think this is just a remnant from the old version of the plugin and should be fixed. I'll go through the FAQ tonight and fix things, and while I greatly appreciate the PR I can unfortunately not accept it because of the semantics behind Lazy properties, I would happily accept a PR updating this entry in the FAQ 🙂

lhhong commented 1 year ago

Thanks! That works. PR-ed an update to the FAQ.