node-gradle / gradle-node-plugin

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

How to handle grunt tasks #314

Closed arjun1607 closed 5 months ago

arjun1607 commented 5 months ago

Project I'm currently working on is using old plugin: 'com.moowork.grunt' and I want to migrate it to 'com.github.node-gradle.node' as part of gradle upgrade to 7.6 from 6.6.1 I this read the grunt doc in FAQ but still I am not able to understand how to migrate my older grunt task code, I m beginner please help.

this was my older code with moowork plugin -

apply plugin: 'com.moowork.grunt'
grunt {
    workDir = file("${project.projectDir}")
    colors = true
    bufferOutput = false 
}
grunt_bowercopy.dependsOn 'npmInstall'
grunt_copy.dependsOn 'npmInstall'
war.dependsOn grunt_bowercopy
war.dependsOn grunt_copy
war.dependsOn grunt_less
war.dependsOn grunt_stylus

I tried doing like this -

apply plugin: 'com.github.node-gradle.node'
task buildWebapp(type: NpxTask) {
    dependsOn npmInstall
    command = "grunt"
    args = ['bowercopy', 'copy', 'less', 'stylus']
}

war.dependsOn buildWebapp

I want to ask a question that there are other grunt tasks mentioned in gruntfile.js like lesslint, stylint, watch, concat and uglify so do i need to mention all of them in arguments? or just the tasks on which war depends like mentioned in old plugin code. I am confused how old plugin is working was it running all the tasks in gruntfile.js? If that is so then i think i need to add all tasks in arguments.

arjun1607 commented 5 months ago

could you please help me in this @deepy @scroix @wansoon

deepy commented 5 months ago

The second one looks correct, but it's missing inputs (and potentially outputs as well)

The old plugin had code to automatically create these tasks for you, and the biggest downside of the automatic task creation is that they're missing out on vital configuration And the easiest way forward is to register a NpxTask for each of your grunt tasks, but if you want the automatic creation you can either parse the Gruntfile in your build-script and register the tasks, or create a rule that sets them up based on name

Getting the inputs and outputs right gets you a lot of nice things for free in Gradle (like automatic task dependencies and only running the task when necessary) https://docs.gradle.org/current/userguide/incremental_build.html#sec:task_input_output_side_effects