本文介绍了如何运行新的 gradle 任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 build.gradle 中创建了一个新的 gradle 任务:

task callCL(type: Exec) {打印你好"命令行'./rerun.sh'}

假设运行 rerun.sh:

#!/bin/bash黄瓜 -f 重新运行 --out rerun.txt文件=重新运行.txt"如果 [ -f "$file" ] 那么黄瓜@rerun.txtrm $文件菲

我使用 IntelliJ 作为 IDE.如何运行此任务?

我尝试在 zshell 控制台中运行并收到此错误:

gradle callCLzsh:找不到命令:gradle

但在 IDE 中我一直使用 gradle,所以必须安装它.

我该如何解决这个问题?我的文笔还好吗?

解决方案

试试这个:
1. 确保设置了 GRADLE_HOME、GRADLE_OPTS.
2. 确保 $PATH 中有 GRADLE_HOME/bin.
3. 哪个 gradle 应该返回一个有效的输出.
4. 然后,见下文
,如果这在命令提示符下有效,那么您的 IDE 设置只需要知道 GRADLE_HOME 又名其已安装/可执行文件(gradle 或 gradle.bat)在哪里

注意:我用了我自己的虚拟rerun.sh文件,你可以用build.gradle(如下图).

$ cat rerun.sh

#!/bin/bashecho 我正在重新运行命令 echo回声回声...回声

$ cat build.gradle

task callCL(type: Exec) {打印-----"打印你好"打印-----"可执行的bash"参数-c",bash ./rerun.sh"//下面的效果和bash中的magic number已经设置为#!/bin/bash一样//参数 "-c", "./rerun.sh"}

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

-----你好-----:callCL我重新运行命令回显某物...建造成功总时间:2.006 秒

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:

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?

解决方案

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

这篇关于如何运行新的 gradle 任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 08:55