GR

Groovy Defaults

Core Groovy coding conventions

Details

Language / Topic
groovyGroovy
Category
Style Guide

Rules

balanced
- Use `camelCase` for methods and variables, `PascalCase` for class names, and `UPPER_SNAKE_CASE` for constants declared with `static final`.
- Prefer Groovy's optional typing (`def`) for local variables and closures, but use explicit types for public API method signatures.
- Use GStrings (`"Hello, ${name}!"`) for interpolation rather than string concatenation — avoid `"${simple_variable}"` and use `"$simple_variable"` instead.
- Use `?.` safe navigation and `?:` Elvis operator to handle nullable values concisely without explicit null checks.
- Prefer Groovy collections API (`collect`, `findAll`, `groupBy`, `inject`) over Java-style `for` loops for data transformation.
- Use `@CompileStatic` on performance-sensitive classes to enable static type checking and improve runtime performance.
- Use `@Canonical`, `@Immutable`, or `@ToString` AST transformations instead of manually writing boilerplate `equals`, `hashCode`, and `toString` methods.