Appendices: Projects, Review Questions, Cheat Sheet & Resources

Capstone projects, interview and review questions, a Groovy cheat sheet, Groovy for Java / Python / Kotlin developers, and resources.

Appendix A: Capstone Projects

Beginner: File Organizer Script. Walk a directory, group files by extension or date into folders, dry-run mode with CliBuilder, logging, and Spock tests.

Beginner: Contact Book CLI. Maps/lists, JSON persistence with JsonSlurper/JsonOutput, searching with GDK methods.

Intermediate: Log Analyzer. Regex parsing of web server logs, groupBy/countBy statistics, GINQ queries, HTML report via MarkupBuilder.

Intermediate: REST API Client and Reporter. Call the GitHub API with HttpClient, parse JSON, generate a Markdown/HTML report from templates, and schedule it.

Intermediate: Database Migration Tool. groovy.sql with transactions and batch inserts, CSV import/export, and a ConfigSlurper environment config.

Advanced: Configuration DSL. A typed DSL with @DelegatesTo, @CompileStatic, validation, and a custom base script. Load DSL files with GroovyShell + SecureASTCustomizer.

Advanced: Custom AST Transformation Library. @Timed, @Retry(times = 3), and @ValidateArgs annotations with tests (assertScript, @ASTTest), packaged as a Gradle library.

Advanced: Rule Engine. Business rules written as Groovy scripts, loaded with GroovyScriptEngine (hot reload), sandboxed, with an execution timeout and an audit log.

Advanced: Web Application. Grails or Micronaut + GORM/Micronaut Data: CRUD, authentication, REST endpoints, Spock + Geb tests, Docker deployment.

DevOps: CI/CD Pipeline Library. A Jenkins shared library (vars + src), declarative pipelines for build/test/deploy, unit-tested with JenkinsPipelineUnit.

Build Engineering: Gradle Plugin. A custom Gradle plugin in Groovy with an extension DSL, tasks with inputs/outputs (incremental), and TestKit functional tests.

Data: Bioinformatics/ETL Workflow. A Nextflow pipeline or GPars-based parallel ETL processing large CSV/JSON files.

Appendix B: Interview and Review Questions

What is Groovy, and how does it relate to Java?

What's optional in Groovy syntax (semicolons, parentheses, return, types)?

Difference between def, var, and explicit types?

Single quotes vs double quotes vs triple quotes vs slashy strings? What is a GString?

What is Groovy Truth? Give examples of falsy values.

Explain ?., ?:, *., <=>, ==~, =~, .&, .@, in, as.

How does == differ between Java and Groovy? How do you test identity?

What's special about Groovy's switch? Name the kinds of case values.

Why does 7 / 2 give 3.5? What is the default decimal type?

How do lists, maps, and ranges look in Groovy? What implementation classes back them?

Closures and Collections What is a closure? What is it?

Explain this, owner, and delegate, and the resolve strategies.

What are currying, composition, memoization, and trampolining for closures?

Difference between each, collect, findAll, find, inject, and groupBy?

Why can't you break out of each? What are the alternatives?

What is SAM coercion?

How do properties work? What is generated for a field without a modifier?

How do named-argument constructors work?

What are traits? How do they differ from interfaces and abstract classes? How are conflicts resolved?

What are records and sealed types in Groovy 4?

What are multi-methods (runtime dispatch)?

How does a script differ from a class? What is the binding? What does @Field do?

@TypeChecked vs @CompileStatic: trade-offs?

Name ten built-in AST transformations and what they do.

What is the MOP? How do invokeMethod, methodMissing, and propertyMissing work?

ExpandoMetaClass vs categories vs extension modules: when do you use each?

Local vs global AST transformations? In which compile phases do they run?

How do you build a DSL in Groovy? What role do @DelegatesTo and command chains play?

How do builders work (MarkupBuilder, JsonBuilder, BuilderSupport)?

What is GINQ? Show a group-by query.

JsonSlurper vs JsonOutput vs JsonGenerator? XmlSlurper vs XmlParser?

How does groovy.sql.Sql prevent SQL injection with GStrings?

How do you embed Groovy in a Java app? GroovyShell vs GroovyClassLoader vs GroovyScriptEngine vs JSR-223?

How do you sandbox untrusted scripts?

Explain Spock's blocks, data tables, and interaction-based testing.

Declarative vs scripted Jenkins pipelines? What is CPS, and when do you need @NonCPS?

How do you improve Groovy performance?

What changed in Groovy 4 (coordinates, packages, indy, new features)? What about Groovy 5?

Count word frequencies in a text file and print the top 5 using GDK methods.

Write a closure-based retry utility: retry(3) { riskyCall() }.

Implement a methodMissing-based dynamic finder (findByNameAndAge).

Create an HTML report with MarkupBuilder from a list of maps.

Write a Spock spec with a data table for a isPalindrome method.

Build a small configuration DSL with nested closures and @DelegatesTo.

Convert a CSV file to JSON with custom field mapping.

Appendix C: Groovy Cheat Sheet

// ===== Variables & strings =====
def x = 1; var y = 2; String s = 'plain'; def g = "x=$x, y=${y + 1}"
def multi = """multi
line"""; def re = /\d+/
def (a, b) = [1, 2]

// ===== Collections =====
def list = [1, 2, 3]; list << 4; list[-1]; list[1..2]
def map = [k: 'v', n: 1]; map.k; map['n']; map.new = true
def range = 1..10; def set = [1, 1, 2] as Set

// ===== Closures =====
def sq = { it * it }; def add = { p, q -> p + q }
list.each { println it }
list.collect { it * 2 }; list.findAll { it > 1 }; list.find { it > 1 }
list.inject(0) { acc, v -> acc + v }; list.groupBy { it % 2 }
list.sum(); list.max(); list.sort { -it }; list*.toString()

// ===== Operators =====
obj?.prop; val ?: 'default'; a <=> b; 'abc' ==~ /a.c/; x in list; obj.&method; a === b

// ===== Control flow =====
if (list) {}                       // Groovy truth
switch (v) { case Integer: break; case 1..5: break; case ~/re/: break; case { it > 9 }: break }
for (i in 0..<3) {}; 3.times {}; while (cond) {}

// ===== Methods =====
def greet(name = 'World') { "Hello $name" }
def opts(Map m) { m.a }; opts(a: 1, b: 2)

// ===== Classes =====
@groovy.transform.Canonical class Person { String name; int age }
def p = new Pe
…
groovy script.groovy | groovy -e "println 1+1" | groovysh | groovyConsole | groovyc File.groovy
sdk install groovy | gradle init --type groovy-application | gradle test

Appendix D: Groovy for Java / Python / Kotlin Developers

val/var x = 1 "$x" / "${expr}" List.of(1, 2) listOf(1, 2) Map.of("a", 1) mapOf("a" to 1) lambda x: x * 2 { x -> x * 2 } { x -> x * 2 } / { it * 2 } record / @Canonical / @Immutable metaClass / categories / extension modules dynamic + optional static Key gotchas:

Java devs: == means equals, decimals are BigDecimal by default, 'a' is a String (not a char), checked exceptions aren't enforced, and fields without modifiers become properties.

Python devs: Groovy runs on the JVM and uses braces (not indentation), 0/empty are falsy just like Python, and closures play the role of both lambdas and blocks.

Kotlin devs: there's no compile-time null safety (?. is a runtime operator), it's dynamic by default (use @CompileStatic for Kotlin-like guarantees), and Groovy DSLs rely on runtime delegation.

Appendix E: Resources

groovy-lang.org: Documentation (language spec, GDK API, user guides for each module), release notes, download

groovy.apache.org: Apache project site. github.com/apache/groovy (source mirror). issues.apache.org/jira/browse/GROOVY

Groovy Web Console (online execution), spockframework.org, gradle.org, jenkins.io/doc/book/pipeline, grails.apache.org, micronaut.io

*Groovy in Action, 2nd Edition*: Dierk König, Paul King, et al. (the definitive book)

*Programming Groovy 2*: Venkat Subramaniam *Making Java Groovy*: Ken Kousen

*Groovy for Domain-Specific Languages*: Fergal Dearle *Spock: Up and Running*: Rob Fletcher

*Java Testing with Spock*: Konstantinos Kapelonis *Jenkins 2: Up and Running*: Brent Laster Learning and Practice

Exercism Groovy track, Groovy Koans, Paul King's talks (Groovy 4/5 features, GINQ, data science with Groovy), Mr. Haki's "Groovy Goodness" blog (hundreds of short recipes), Baeldung's Groovy articles Suggested 8-Week Study Plan Setup, syntax, types, numbers Strings, operators, control flow

Collections, closures, GDK, methods, regex OOP, traits, records, scripts, exceptions, coercion

Static typing, AST transforms, MOP, compile-time metaprogramming DSLs, builders, GINQ, FP, concurrency

Files, JSON/XML/YAML, SQL, templates, processes, CLI 39–48 + Capstone

Java integration, Spock, Gradle, Jenkins, Grails/Micronaut, performance, security, best practices

Final tip: Keep the GDK docs open (most "how do I…" questions are answered by an existing GDK method), learn closures and delegation deeply (they're the key to Gradle, Jenkins, and Spock), use @CompileStatic where performance matters, and write your tests in Spock. Happy grooving! 🎸