How can I run new gradle task?

2019-02-20 00:36发布

I have created a new gradle task in build.gradle:

task callCL(type: Exec) {
   println "hello"
   commandLine './rerun.sh'
}

Which suppose to run rerun.sh:

#!/bin/bash

cucumber -f rerun --out rerun.txt

file="rerun.txt"
if [ -f "$file" ] then
    cucumber @rerun.txt
    rm $file
fi

I'm using IntelliJ as an IDE. How can I run this task?

I have tried to run in the zshell console and got this error:

gradle callCL zsh: command not found: gradle

But in the IDE I use gradle all the time so it must be installed.

How can I fix this? And is my writing ok?

2条回答
可以哭但决不认输i
2楼-- · 2019-02-20 01:15

Try this:
1. Make sure GRADLE_HOME, GRADLE_OPTS are set.
2. Make sure $PATH has GRADLE_HOME/bin in it.
3. which gradle should return you a valid output.
4. then, see below
, if this works on command prompt, then your IDE setting just need to know where's is GRADLE_HOME aka its installed / executable (either gradle or gradle.bat)

NOTE: I have used my own dummy rerun.sh file, you can you use build.gradle (as shown below).

$ cat rerun.sh

#!/bin/bash

echo Im re-running a command echo
echo something
echo ...
echo

$ cat build.gradle

task callCL(type: Exec) {
        println "-----"
        println "hello"
        println "-----"
        executable "bash"
        args "-c", "bash ./rerun.sh"

        //The following will do as well as magic number in bash is already set to #!/bin/bash
        //args "-c", "./rerun.sh"
}

$ /cygdrive/c/gradle-2.0/bin/gradle callCL

-----
hello
-----
:callCL
Im re-running a command echo
something
...

BUILD SUCCESSFUL

Total time: 2.006 secs
查看更多
男人必须洒脱
3楼-- · 2019-02-20 01:31

This looks like problem with gradle not being found on path (in your shell).

You may use GVM to easily install gradle so that its available on your PATH.

查看更多
登录 后发表回答