super cool groovy

task groovy << {}

def noArgs(){
	println "Called the no args function"
}

def oneArg(x) {
	println "Called the 1 arg function with $x"
	x
}

def twoArgs(x, y){
	println "Called the  2 arg function with $x and $y"
	x + y
}

oneArg 500
[vagrant@localhost ud867]$ gradle groovy
Called the 1 arg function with 500
:groovy

BUILD SUCCESSFUL

Total time: 7.983 secs

Hey, what?

task groovy << {}

def noArgs(){
	println "Called the no args function"
}

def oneArg(x) {
	println "Called the 1 arg function with $x"
	x
}

def twoArgs(x, y){
	println "Called the  2 arg function with $x and $y"
	x + y
}

twoArgs 200, 300
[vagrant@localhost ud867]$ gradle groovy
Called the  2 arg function with 200 and 300
:groovy

BUILD SUCCESSFUL

Total time: 6.671 secs
task groovy << {}

def noArgs(){
	println "Called the no args function"
}

def oneArg(x) {
	println "Called the 1 arg function with $x"
	x
}

def twoArgs(x, y){
	println "Called the  2 arg function with $x and $y"
	x + y
}

twoArgs oneArg(500), 100
[vagrant@localhost ud867]$ gradle groovy
Called the 1 arg function with 500
Called the  2 arg function with 500 and 100
:groovy

BUILD SUCCESSFUL

Total time: 6.277 secs

groovy groovy groovy

task groovy << {}

def foo = 6.5

println "foo has value. $foo"
println "Let's do same math. 5 + 6 = ${5 + 6}"
println "foo is of type: ${foo.class} and has value: $foo"

foo = "a string"
println "foo is new of type: ${foo.class} and has value: $foo"
[vagrant@localhost ud867]$ gradle groovy
Hello Java!
:groovy

BUILD SUCCESSFUL

Total time: 6.464 secs
[vagrant@localhost ud867]$ gradle groovy
foo has value. 6.5
Let's do same math. 5 + 6 = 11
foo is of type: class java.math.BigDecimal and has value: 6.5
foo is new of type: class java.lang.String and has value: a string
:groovy

BUILD SUCCESSFUL

Total time: 6.531 secs
task groovy << {}

def doubleIt(n){
	n + n // Note we don't need a return statement
}

def foo = 5
println "doubleIt($foo) = ${doubleIt(foo)}"

foo = "foobar"
println "doubleIt($foo) = ${doubleIt(foo)}"
[vagrant@localhost ud867]$ gradle groovy
doubleIt(5) = 10
doubleIt(foobar) = foobarfoobar
:groovy

BUILD SUCCESSFUL

Total time: 6.396 secs

Groovy Fundamentals

build.gradle

task groovy << {}
[vagrant@localhost ud867]$ gradle groovy
:groovy

BUILD SUCCESSFUL

Total time: 9.107 secs

task groovy << {}

println "Hello Groovy!"
task groovy << {}

class JavaGreeter {
	public static void sayHello(){
		System.out.println("Hello Java!");
	}
}

JavaGreeter greeter = new JavaGreeter()
greeter.sayHello()

Gradle Daemon

[root@localhost src]# gradle --stop
No Gradle daemons are running.
[root@localhost src]# gradle hello World
Starting a Gradle Daemon (subsequent builds will be faster)

FAILURE: Build failed with an exception.

* What went wrong:
Task 'hello' not found in root project 'src'. Some candidates are: 'help'.

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

Total time: 7.419 secs
[root@localhost src]# gradle hello World

FAILURE: Build failed with an exception.

* What went wrong:
Task 'hello' not found in root project 'src'. Some candidates are: 'help'.

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

Total time: 1.66 secs