Using Groovy in Gradle's tasks: Build Failed

Using Groovy in Gradle’s tasks: Build Failed

I am using Windows 7 (32 Bit OS) in DELL Vostro with Intel i5 Pentium.

I set GRADLEHOME as C:\Gradle\gradle-2.1-all and add to PATH = %GRADLEHOME%\bin

I saved build.gradle in the path C:\Gradle\gradle-2.1-all\gradle-2.1\bin

build.gradle

task upper << {

String someString = ‘Deepika’

println "Original: " + someString

println "Upper case: " + someString.toUpperCase() }

Expected Output of gradle -q upper should be:

gradle -q upper Original: Deepika Upper case: DEEPIKA

Actual Output is: Build Failed

Command Line Output is given below:

Microsoft Windows [Version 6.1.7601] Copyright © 2009 Microsoft Corporation. All rights reserved.

C:\Users\Dell>gradle -v ‘gradle’ is not recognized as an internal or external command, operable program or batch file.

C:\Users\Dell>cd…

C:\Users>cd…

C:>cd Gradle

C:\Gradle>cd gradle-2.1-all

C:\Gradle\gradle-2.1-all>cd gradle-2.1

C:\Gradle\gradle-2.1-all\gradle-2.1>cd bin

C:\Gradle\gradle-2.1-all\gradle-2.1\bin>gradle -v

------------------------------------------------------------ Gradle 2.1 ------------------------------------------------------------

Build time:

2014-09-08 10:40:39 UTC Build number: none Revision:

e6cf70745ac11fa943e19294d19a2c527a669a53

Groovy:

2.3.6 Ant:

Apache Ant™ version 1.9.3 compiled on December 23 2013 JVM:

1.8.0_20 (Oracle Corporation 25.20-b23) OS:

Windows 7 6.1 x86

C:\Gradle\gradle-2.1-all\gradle-2.1\bin>gradle -q hello Hello Rohan! C:\Gradle\gradle-2.1-all\gradle-2.1\bin>gradle -q hello

FAILURE: Build failed with an exception.

  • Where: Build file ‘C:\Gradle\gradle-2.1-all\gradle-2.1\bin\build.gradle’ line: 1

  • What went wrong: Could not compile build file ‘C:\Gradle\gradle-2.1-all\gradle-2.1\bin\build.grad le’. > startup failed:

build file ‘C:\Gradle\gradle-2.1-all\gradle-2.1\bin\build.gradle’: 1: expectin g EOF, found ‘hello’ @ line 1, column 6.

task hello << (

^

1 error

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

C:\Gradle\gradle-2.1-all\gradle-2.1\bin>gradle -q upper

FAILURE: Build failed with an exception.

  • Where: Build file ‘C:\Gradle\gradle-2.1-all\gradle-2.1\bin\build.gradle’ line: 3

  • What went wrong: Execution failed for task ‘:upper’. > Could not find property ‘println’ on task ‘:upper’.

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

C:\Gradle\gradle-2.1-all\gradle-2.1\bin>gradle --stacktrace upper :upper FAILED

FAILURE: Build failed with an exception.

  • Where: Build file ‘C:\Gradle\gradle-2.1-all\gradle-2.1\bin\build.gradle’ line: 3

  • What went wrong: Execution failed for task ‘:upper’. > Could not find property ‘println’ on task ‘:upper’.

  • Try: Run with --info or --debug option to get more log output.

  • Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:upper’.

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecuteActions(ExecuteActionsTaskExecuter.java:69)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecute(ExecuteActionsTaskExecuter.java:46)

at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec uter.execute(PostExecutionAnalysisTaskExecuter.java:35)

at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec ute(SkipUpToDateTaskExecuter.java:64)

at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut e(ValidatingTaskExecuter.java:58)

at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu ter.execute(SkipEmptySourceFilesTaskExecuter.java:42)

at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter .execute(SkipTaskWithNoActionsExecuter.java:52)

at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut e(SkipOnlyIfTaskExecuter.java:53)

at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter .execute(ExecuteAtMostOnceTaskExecuter.java:43)

at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailur e(AbstractTask.java:305)

at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW orker.executeTask(AbstractTaskPlanExecutor.java:79)

at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW orker.processTask(AbstractTaskPlanExecutor.java:63)

at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW orker.run(AbstractTaskPlanExecutor.java:51)

at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(Defaul tTaskPlanExecutor.java:23)

at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(Defau ltTaskGraphExecuter.java:88)

at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTask ExecutionAction.java:29)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:62)

at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec uter.java:23)

at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu ter.java:68)

at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildEx ecutionAction.java:32)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:62)

at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute r.java:55)

at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default GradleLauncher.java:149)

at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle Launcher.java:106)

at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun cher.java:86)

at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon troller.run(InProcessBuildActionExecuter.java:80)

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:36)

at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce ssBuildActionExecuter.java:26)

at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)

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 ‘printl n’ on task ‘:upper’.

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.api.DefaultTask_Decorated.getProperty(Unknown Source)

at build_1gfq59mv0e7u52qg4p05lpi9dk$_run_closure1.doCall(C:\Gradle\gradl e-2.1-all\gradle-2.1\bin\build.gradle:3)

at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(Abstra ctTask.java:548)

at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(Abstra ctTask.java:529)

at org.gradle.api.internal.tasks.TaskMutator$1.execute(TaskMutator.java: 77)

at org.gradle.api.internal.tasks.TaskMutator$1.execute(TaskMutator.java: 73)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecuteAction(ExecuteActionsTaskExecuter.java:80)

at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex ecuteActions(ExecuteActionsTaskExecuter.java:61)

… 44 more

BUILD FAILED

Total time: 3.737 secs

C:\Gradle\gradle-2.1-all\gradle-2.1\bin>

Regards

Rohan Sarker

+913324288069 / +917278539338

www.rohansarker.com

Your first error is due to using a parenthesis instead of a curly brace to define your task action closure. You defined the task like ‘task hello << (’ when it should be ‘task hello << {’.

Something is likely wrong with your PATH setup (looks like GRADLEHOME is missing ‘\gradle-2.1’). Also, you shouldn’t put build scripts inside the Gradle installation dir.

Problem rectified. gradle is working now.

Microsoft Windows [Version 6.1.7601] Copyright © 2009 Microsoft Corporation. All rights reserved.

C:\Users\Dell>cd…

C:\Users>cd…

C:>cd Gradle

C:\Gradle>cd gradle-2.1-all

C:\Gradle\gradle-2.1-all>cd gradle-2.1

C:\Gradle\gradle-2.1-all\gradle-2.1>cd bin

C:\Gradle\gradle-2.1-all\gradle-2.1\bin>gradle -q upper

FAILURE: Build failed with an exception.

  • Where: Build file ‘C:\Gradle\gradle-2.1-all\gradle-2.1\bin\build.gradle’ line: 3

  • What went wrong: Execution failed for task ‘:upper’. > Could not find property ‘println’ on task ‘:upper’.

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

C:\Gradle\gradle-2.1-all\gradle-2.1\bin>gradle -q upper Original: mY_nAmE Upper case: MY_NAME C:\Gradle\gradle-2.1-all\gradle-2.1\bin>gradle -q upper Original: Deepika Upper case: DEEPIKA C:\Gradle\gradle-2.1-all\gradle-2.1\bin>

Regards Rohan Sarker +913324288069 +917278539338 +919674221741 www.rohansarker.com