Running grunt with gradle

I'm having trouble getting gradle to run grunt. I'm using Windows and cygwin and the grunt is clearly in the way:

depressio@depressio /cygdrive/c/dev/project
$ which grunt
/cygdrive/c/Users/depressio/AppData/Roaming/npm/grunt

      

So I am doing this gradle task:

task execGrunt(type: Exec) {
    workingDir './ui'
    commandLine 'grunt'
}

      

Simple enough. However, when I run it, I get this exception:

Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'grunt''
    at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:195)
    at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:325)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:90)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
Caused by: java.io.IOException: Cannot run program "grunt" (in directory "C:\dev\project\ui"): CreateProcess error=2, The system cannot find the file specified
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:71)
    ... 1 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    ... 2 more

      

Why? When I go to ./ui

myself, I can run grunt just fine (grunt.js is there).

Some suggestions I have found contain a definition for commandLine

how 'cmd', '/c', 'grunt'

, but instead it just opens grunt.js in an editor. Also, this won't work on UNIX, and I would like this task to work on both Windows (cygwin) and UNIX if the PATH is set correctly.

It is clear that I missed something.

Update:

While this doesn't work for UNIX, I've tried using 'grunt.cmd'

just instead 'grunt'

. This didn't work either, but gave a different stack trace:

Caused by: org.gradle.process.internal.ExecException: Process 'command 'grunt.cmd'' finished with non-zero exit value 3
    at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:363)
    at org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:39)
    at org.gradle.api.tasks.Exec.exec(Exec.java:66)

      

(there is more, but this is the lowest "caused")

It seems like doing a grunt at least, however, is evidenced by the fact that my coffee pot was compiled to js and this line appeared: Running "clean:0" (clean) task

+3


source to share


3 answers


I used grunt

on Windows when I had to use grunt.cmd

. Once I did this and figured out why the coffee is failing (why the grunt is failing), it looks like it works fine.



However, it grunt.cmd

is only intended for Windows. I found this question and answer that provided an OS detection capability.

+2


source


EDIT: This article is very timely and is a much better solution than using my old answer below.

The Gradle devs may hate me for this, but I am not using the task Exec

, I am doing this instead:



task execGrunt {
    doLast {
        println "grunt".execute().text
    }
}

      

See the Groovy docs for external processes for details . By the way, the reason for your last failure is Grunt returning an exit code that says it worked (not zero).

+1


source


You can use this gradle plugin: https://plugins.gradle.org/plugin/com.moowork.grunt

0


source







All Articles