gpt4 book ai didi

Gradle Hello World 错误

转载 作者:行者123 更新时间:2023-12-04 04:04:43 26 4
gpt4 key购买 nike

我在 Gradle 中尝试了我的第一个程序,但出现错误。我写了一个 hello world 脚本,但我无法运行它。

我的毕业细节是:

------------------------------------------------------------
Gradle 2.0
------------------------------------------------------------

Build time: 2014-07-01 07:45:34 UTC
Build number: none
Revision: b6ead6fa452dfdadec484059191eb641d817226c

Groovy: 2.3.3
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_11 (Oracle Corporation 25.11-b03)
OS: Windows 7 6.1 x86

我的 build.gradle 是:
task hello << {
println 'Hello world!'
}

当我跑 gradle -q --info hello ,我收到以下错误:
Starting Build
Settings evaluated using empty settings script.
Projects loaded. Root project using build file 'D:\Gradle\build.gradle'.
Included projects: [root project 'Gradle']
Evaluating root project 'Gradle' using build file 'D:\Gradle\build.gradle'.

FAILURE: Build failed with an exception.

* Where:
Build file 'D:\Gradle\build.gradle' line: 1

* What went wrong:
A problem occurred evaluating root project 'Gradle'.
> Could not find property 'hello' on root project 'Gradle'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to
get more log output.

BUILD FAILED

Total time: 7.048 secs

堆栈跟踪如下:
Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project
'Gradle'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptR
unnerImpl.run(DefaultScriptRunnerFactory.java:54)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.
apply(DefaultScriptPluginFactory.java:187)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildSc
riptProcessor.java:39)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildSc
riptProcessor.java:26)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.eva
luate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(L
ifecycleProjectEvaluator.java:55)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProj
ect.java:470)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProj
ect.java:79)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuil
dConfigurer.java:31)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
GradleLauncher.java:128)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
Launcher.java:105)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
cher.java:85)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon
troller.run(InProcessBuildActionExecuter.java:81)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:39)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:29)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.jav
a:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:237)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:35)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:24)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:206)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots
trap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
ava:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: groovy.lang.MissingPropertyException: Could not find property 'hello'
on root project 'Gradle'.
at org.gradle.api.internal.AbstractDynamicObject.propertyMissingExceptio
n(AbstractDynamicObject.java:43)
at org.gradle.api.internal.AbstractDynamicObject.getProperty(AbstractDyn
amicObject.java:35)
at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeD
ynamicObject.java:94)
at org.gradle.groovy.scripts.BasicScript.propertyMissing(BasicScript.jav
a:66)
at build_4hki6gadurnm5c9ejslud0e844.run(D:\Gradle\build.gradle:1)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptR
unnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 31 more


BUILD FAILED

Total time: 26.219 secs
amicObject.java:35)
at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeD
ynamicObject.java:94)
at org.gradle.groovy.scripts.BasicScript.propertyMissing(BasicScript.jav
a:66)
at build_4hki6gadurnm5c9ejslud0e844.run(D:\Gradle\build.gradle:1)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptR
unnerImpl.run(DefaultScriptRunnerFactory.java:52)
... 31 more

最佳答案

我知道现在有点晚了,但是对于那些面临同样问题的人(就像你和我一样),我会发布我的解决方案。

问题出在 build.gradle 编码中,我正在运行 Windows(默认编码 ansi)并且我的 build.gradle 是 UTF-8,我已经更改了 build.gradle 编码以匹配我的操作系统编码,现在一切正常。

关于Gradle Hello World 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25175434/

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