Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Hello World Error

Tags:

gradle

I tried my first program in Gradle but I got an error. I wrote a hello world script but I am unable to run it.

My gradle details are:

------------------------------------------------------------
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

My build.gradle is:

task hello << {
    println 'Hello world!'
}

When I run gradle -q --info hello, I get the following error:

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

The stacktrace is as follows:

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
like image 318
khateeb Avatar asked Aug 07 '14 06:08

khateeb


People also ask

How do I write Hello world in Gradle?

println 'Hello world!' Above script is written in Gradle’s DSL (self descriptive language) e.g. action named doLast is almost self-expressive. It’s the last action that’s executed for a task. To run the script, run the gradle command and pass the task name. Output will be as shown: Hello world!

What happens when you run Gradle Hello?

When you run gradle hello, Gradle executes the hello task, which in turn executes the action you’ve provided. The action is simply a block containing some code to execute. If you think this looks similar to Ant’s targets, you would be right. Gradle tasks are the equivalent to Ant targets, but as you will see, they are much more powerful.

Where does Gradle look for Gradle command?

The gradlecommand looks for a file called build.gradlein the current directory.[1] We call this build.gradlefile a build script, although strictly speaking it is a build configuration script, as we will see later. The build script defines a project and its tasks. To try this out, create the following build script named build.gradle.

How do I write a Gradle task in Groovy?

Gradle tasks can be written using Groovy code from inside a projects build.gradle file. These tasks can then be executed using > gradle [taskname] at the terminal or by executing the task from within an IDE such as Eclipse. To create the Hello World example in gradle we must define a task that will print a string to the console using Groovy.


1 Answers

I know it's a little bit late, but for those who face the same problem (as you and me) i'll post my solution.

The problem is in the build.gradle encoding, i'm running windows (default encoding ansi) and my build.gradle was UTF-8, I've changed the build.gradle encoding to match my OS encoding and everything works fine now.

like image 82
lepi Avatar answered Jan 04 '23 12:01

lepi