我在Gradle尝试了我的第一个程序,但是我收到了一个错误。我写了一个hello world脚本,但我无法运行它。
我的gradle详细信息是:
------------------------------------------------------------
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
答案 0 :(得分:2)
我知道它有点迟了,但对于那些面临同样问题的人(和你我一样),我会发布我的解决方案。
问题在于build.gradle编码,我正在运行Windows(默认编码ansi),而我的build.gradle是UTF-8,我更改了build.gradle编码以匹配我的操作系统编码,现在一切正常。
答案 1 :(得分:0)
要解决此问题,请先尝试使用以下命令构建项目:
gradle build
完成此操作后,通过说:
在gradle文件中运行任务gradle -q hello
gradle -q --info hello
希望这有帮助!
答案 2 :(得分:0)
当我写第一个gradle项目时,我也遇到了这个问题。这是因为你的文件编码。不要复制helloword项目。自己输入这些单词。
任务helloword&lt;&lt; { println&#39; pringln hello word&#39; }
答案 3 :(得分:0)
我要做的就是在gradle中更新kotlin版本,我将其从“ 1.2.40”更改为“ 1.3.72”
buildscript {
ext.kotlin_version = '1.3.72'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}