node-gradle / gradle-node-plugin

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

Val cannot be reassigned #185

Closed SchlauFuchs closed 3 years ago

SchlauFuchs commented 3 years ago

Hi,

I have a Gradle config file in Kotlin DSL, and configuring this plugin is currently failing with such an exception: build.gradle.kts:15:5: Val cannot be reassigned

image

Any recommendations?

rkimmel-hv commented 3 years ago

I am having a very similar problem trying to set the args the way the documentation suggests

named<NpmSetupTask>("npmSetup") {
        // Hack for Gradle node plugin ignoring the project's .npmrc file during npmInstall
        doFirst {
            val npmRegistry = "https://my.registry.here/api/npm/npm/"
            args.set(listOf("--registry", npmRegistry))
        }
}

This ends up causing this failure

> Task :project:npmSetup FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':project:npmSetup'.
> The value for task ':project:npmSetup' property 'args' is final and cannot be changed any further.
deepy commented 3 years ago

It's perhaps a bit hidden in the documentation, but we have a Kotlin DSL example here https://github.com/node-gradle/gradle-node-plugin/blob/master/src/test/resources/fixtures/kotlin/build.gradle.kts

rkimmel-hv commented 3 years ago

It's perhaps a bit hidden in the documentation, but we have a Kotlin DSL example here https://github.com/node-gradle/gradle-node-plugin/blob/master/src/test/resources/fixtures/kotlin/build.gradle.kts

Got it working by removing the doFirst

was confused by this line in the faq https://github.com/node-gradle/gradle-node-plugin/blob/master/docs/faq.md#how-do-i-specify-a-registry-for-the-npm-setup-task

SchlauFuchs commented 3 years ago

Seriously, that helped. :) Maybe take an example in other documentations, where they put code examples in the view both as groovy and kotlin DSL with tabs to switch between.

deepy commented 3 years ago

I haven't toyed a lot with GitHub markdown but I think they have some collapsible thing and we could probably do something like that, but PRs improving documentation is greatly appreciated