gpt4 book ai didi

gradle - 简单的常规程序-Gradle

转载 作者:行者123 更新时间:2023-12-03 06:32:47 34 4
gpt4 key购买 nike

我用一个名为groovy的任务创建了一个非常简单的gradle文件。

task groovy << {}

println "Hello Groovy!"

我尝试在cmd(我正在使用Windows 8.1)的项目文件夹下运行它
gradle groovy

但我得到这个错误:
FAILURE: Build failed with an exception.

What went wrong:
Task 'groovy' not found in root project 'MyExercise'.

Try:
Run gradle tasks to get a list of available tasks. Run with --stacktrace
option
to get the stack trace. Run with --info or --debug option to get more log
output

为什么找不到常规任务?它在我的 build.gradle文件中声明。已安装Gradle。这是我的版本。
Gradle 3.0
------------------------------------------------------------

Build time: 2016-08-15 13:15:01 UTC
Revision: ad76ba00f59ecb287bd3c037bd25fc3df13ca558

Groovy: 2.4.7
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_45 (Oracle Corporation 25.45-b02)
OS: Windows 8.1 6.3 amd64

命令gradle任务显示:
All tasks runnable from root project
------------------------------------------------------------

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared
t 'MyExercise'.
components - Displays the components produced by root project 'MyE
ubating]
dependencies - Displays all dependencies declared in root project
dependencyInsight - Displays the insight into a specific dependenc
ect 'MyExercise'.
help - Displays a help message.
model - Displays the configuration model of root project 'MyExerci
ng]
projects - Displays the sub-projects of root project 'MyExercise'.
properties - Displays the properties of root project 'MyExercise'.
tasks - Displays the tasks runnable from root project 'MyExercise'

To see all tasks and more detail, run gradle tasks --all

To see more detail about a task, run gradle help --task <task>

BUILD SUCCESSFUL

有任何想法吗?

谢谢

西奥

最佳答案

如果我理解正确,那么您的文件未命名为build.gradle。如果是这种情况,那么gradle将不知道groovy任务是什么,因为它没有读取该文件。

如果要指定非build.gradle的文件以通过gradle进行评估,则需要给gradle提供文件名。为了清楚起见,我使用了一个名为test.groovy的文件,并演示了如何在groovy文件中执行任务。

~/temp/39294812 $ cat test.groovy 
task groovy << {
println "Hello to you!"
}

println "Hello groovy"

~/temp/39294812 $ gradle -q -b test.groovy groovy
Hello groovy
Hello to you!

还要注意,如果您只需要将任务添加到另一个 build.gradle中,则可以使用 apply from: <path>
// to call groovy from inside a `build.gradle` file
apply from: 'test.groovy'

关于gradle - 简单的常规程序-Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39294812/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com