Apache Groovy - A powerful multi-faceted programming language for the JVM platform with comprehensive module support
npx @tessl/cli install tessl/maven-org-codehaus-groovy--groovy-all@3.0.0Apache Groovy is a powerful, optionally typed and dynamic language with static-typing and static compilation capabilities for the Java platform. It aims to improve developer productivity thanks to a concise, familiar and easy to learn syntax. The groovy-all package provides the complete Groovy distribution including the core language and all optional modules.
implementation 'org.codehaus.groovy:groovy-all:3.0.25'import groovy.lang.*
import groovy.util.*For Maven dependency:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>3.0.25</version>
</dependency>For Gradle:
implementation 'org.codehaus.groovy:groovy-all:3.0.25'import groovy.lang.GroovyShell
import groovy.lang.Binding
// Create and execute Groovy scripts
def binding = new Binding()
binding.setVariable('name', 'World')
def shell = new GroovyShell(binding)
def result = shell.evaluate('println "Hello, $name!"; return "Done"')
// Use Groovy collections and closures
def numbers = [1, 2, 3, 4, 5]
def doubled = numbers.collect { it * 2 }
def evens = numbers.findAll { it % 2 == 0 }
// Work with dynamic objects
def expando = new groovy.lang.Expando()
expando.name = 'Groovy'
expando.version = '3.0.25'
expando.greet = { "Hello from ${name} ${version}!" }Apache Groovy is organized into several key layers:
groovy.lang)The fundamental Groovy language constructs including script execution, dynamic objects, closures, and metaprogramming facilities.
class GroovyShell {
GroovyShell()
GroovyShell(Binding binding)
GroovyShell(ClassLoader parent, Binding binding)
Object evaluate(String scriptText)
Object evaluate(File scriptFile)
Script parse(String scriptText)
}
class Binding {
Binding()
Binding(Map variables)
Binding(String[] args)
Object getVariable(String name)
void setVariable(String name, Object value)
boolean hasVariable(String name)
void removeVariable(String name)
Map getVariables()
Object getProperty(String property)
void setProperty(String property, Object newValue)
}
abstract class Closure<V> {
Object call(Object... args)
Closure<V> curry(Object... args)
Object getDelegate()
void setDelegate(Object delegate)
}JSON parsing, generation, and manipulation using JsonSlurper and JsonBuilder with configurable parsing strategies.
class JsonSlurper {
JsonSlurper()
Object parseText(String text)
Object parse(File file)
Object parse(URL url)
JsonSlurper setType(JsonParserType type)
int getMaxSizeForInMemory()
JsonSlurper setMaxSizeForInMemory(int size)
}
class JsonBuilder {
JsonBuilder()
JsonBuilder(Object content)
Object call(Closure c)
String toString()
String toPrettyString()
}XML parsing with GPath navigation, DOM manipulation, and markup generation using various XML processing approaches.
class XmlSlurper {
XmlSlurper()
XmlSlurper(boolean validating, boolean namespaceAware)
GPathResult parseText(String text)
GPathResult parse(File file)
GPathResult parse(URL url)
}
class MarkupBuilder {
MarkupBuilder(Writer writer)
Object invokeMethod(String methodName, Object args)
void yield(Object value, boolean escapeMarkup)
}SQL database operations, connection management, and result set processing with Groovy's SQL class and DataSet.
class Sql {
static Sql newInstance(String url, String user, String password, String driverClassName)
static Sql newInstance(DataSource dataSource)
List<GroovyRowResult> rows(String sql, List<Object> params)
void execute(String sql, List<Object> params)
int executeUpdate(String sql, List<Object> params)
void close()
}
class DataSet {
DataSet(Sql sql, String table)
void add(Map<String, Object> values)
List<GroovyRowResult> findAll(Closure where)
int update(Closure where, Map<String, Object> values)
}Template engines for generating dynamic content from templates with variable substitution and embedded code execution.
class SimpleTemplateEngine {
SimpleTemplateEngine()
Template createTemplate(String templateText)
Template createTemplate(File templateFile)
}
interface Template {
Writable make(Map<String, Object> binding)
}
class GStringTemplateEngine {
GStringTemplateEngine()
Template createTemplate(String templateText)
}Compile-time code generation and modification through annotations that transform the Abstract Syntax Tree.
@interface ToString {
boolean includeNames() default false
boolean includeFields() default false
String[] excludes() default {}
String[] includes() default {}
}
@interface CompileStatic {}
@interface TypeChecked {}
@interface Immutable {
String[] excludes() default {}
boolean copyWith() default false
}Command-line argument parsing and processing using PicoCLI integration for building CLI applications.
class CliBuilder {
CliBuilder()
CliBuilder(String usage)
void setUsage(String usage)
OptionAccessor parse(String[] args)
def opt(String opt, String longOpt, String description)
}Swing user interface construction using builder pattern for creating desktop applications with Groovy.
class SwingBuilder {
SwingBuilder()
Object invokeMethod(String name, Object args)
JFrame frame(Map<String, Object> attributes, Closure content)
JPanel panel(Map<String, Object> attributes, Closure content)
}interface GroovyObject {
Object invokeMethod(String name, Object args)
Object getProperty(String property)
void setProperty(String property, Object newValue)
MetaClass getMetaClass()
void setMetaClass(MetaClass metaClass)
}
abstract class Script {
abstract Object run()
Object getProperty(String property)
void setProperty(String property, Object newValue)
Binding getBinding()
void setBinding(Binding binding)
}
class Expando implements GroovyObject {
Expando()
Expando(Map<String, Object> properties)
}
abstract class GString implements Comparable, CharSequence, Writable {
Object[] getValues()
String[] getStrings()
String toString()
}class IntRange implements Range<Integer> {
IntRange(int from, int to)
IntRange(boolean inclusive, int from, int to)
boolean contains(Object value)
List<Integer> step(int stepSize)
}
class ObjectRange implements Range<Comparable> {
ObjectRange(Comparable from, Comparable to)
ObjectRange(Comparable from, Comparable to, boolean inclusive)
}class GroovyRuntimeException extends RuntimeException {
GroovyRuntimeException(String message)
GroovyRuntimeException(String message, Throwable cause)
}
class MissingMethodException extends GroovyRuntimeException {
MissingMethodException(String method, Class type, Object[] arguments)
String getMethod()
Class getType()
}
class MissingPropertyException extends GroovyRuntimeException {
MissingPropertyException(String property, Class type)
String getProperty()
Class getType()
}