如何运行新的 gradle 任务?

2024-01-14

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

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

假设运行 rerun.sh:

#!/bin/bash

cucumber -f rerun --out rerun.txt

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

我正在使用 IntelliJ 作为 IDE。我怎样才能运行这个任务?

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

gradle 调用CL zsh:找不到命令:gradle

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

我怎样才能解决这个问题?还有我的文笔还好吗?


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

NOTE:我使用了我自己的虚拟rerun.sh文件,你可以使用build.gradle(如下所示)。

$猫重新运行.sh

#!/bin/bash

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

$ 猫构建.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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何运行新的 gradle 任务? 的相关文章