Patrick van Dissel
A multi-faceted language
for the Java platform
Groovy is a powerful,
optionally typed and dynamic language,
with static-typing and static compilation
capabilities, for the Java platform
aimed at
multiplying developers’ productivity thanks to a
concise, familiar and easy to learn syntax.
It integrates smoothly with any Java program, and
immediately delivers to your application
powerful features,
including scripting capabilities,
Domain-Specific Language authoring,
runtime and compile-time meta-programming and
functional programming.
Java compatible
Enhanced Java-syntax
Dynamic
Scriptable
Superset of Java
import java.io.*;
import java.lang.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.*;
import java.util.*;
import groovy.lang.*;
import groovy.util.*;
int method(String arg) { return 1; }
int method(Object arg) { return 2; }
Object o = "Object";
int result = method(o);
assertEquals(2, result);
vs
assertEquals(1, result);
int[] array = { 1, 2, 3 };
vs
int[] array = [ 1, 2, 3 ];
class Person {
String name
}
vs
class Person {
@PackageScope String name
}
Path file = Paths.get("/path/to/file");
Charset charset = Charset.forName("UTF-8");
try (BufferedReader reader = Files.newBufferedReader(file, charset)) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
vs
new File('/path/to/file').eachLine('UTF-8') {
println it
}
Runnable run = () -> System.out.println("Run");
list.forEach(System.out::println);
vs
Runnable run = { println 'run' }
list.each(this.&println)
list.each { println it } // preferred, for simple cases
list.each { item -> println item } // preferred
int val = 2;
assert "c".getClass() == String.class;
assert false == "c${val}".equals("c2");
assert true == ("c" + val).equals("c2");
vs
def val = 2
assert 'c'.class == String
assert "c".class == String
assert "c${val}".class in GString
// for single char strings, both are the same
assert ((char) "c").class == Character
assert ("c" as char).class == Character
// for multi char strings they are not
try {
((char) 'cx') == 'c'
assert false: 'will fail - not castable'
} catch (GroovyCastException e) {
}
assert ('cx' as char) == 'c'
assert 'cx'.asType(char) == 'c'
==
String a = new String("a");
String b = new String("a");
assert a != b;
assert true == a.equals(b);
vs
String a = new String("a")
String b = new String("a")
assert a == b
assert true == a.equals(b)
assert false == a.is(b)
in
trait
Open Source Build Automation
From command line to IDE
to continuous integration, only one
Enterprise build automation system to rule them all.
Declare and execute all tasks necessary to
compile, test, package and ship
multi-language multi-platform
multi-project and multi-channel
software, SaaS and Mobile Apps.
We’ve got a Maven, Java, Junit project:
Lets migrate it to Gradle, Groovy, Spock:
Cache everything
Incremental build
Parallelize
Gradle Daemon
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true
Release | Initial | Cycle |
---|---|---|
Java | 1995 | ~2 years |
Ant | 2000 | month <-> year |
Maven | 2002 | month <-> year |
Ivy | 2004 | month <-> year |
Gradle | 2009 | ~6 weeks |
sbt | 2011 | days <-> months |
Java compatible
Enhanced Java-syntax
Dynamic
Scriptable
Polyglot builds
Tool integrations
Robust dependency management
Powerful yet concise logic
High performance builds
Slides & code
ikoodi.nl/talks
github.com/pvdissel/talks