Skip to content
AgileLogics
6 min read

Project Structure, Tooling, and Deployment

Prerequisites: Gradle build scripts, Testing with Spock

Scripts are single files; applications and libraries follow the standard Gradle (or Maven) layout.

Project layout

inventory/
├── build.gradle
├── settings.gradle
├── gradlew, gradlew.bat, gradle/wrapper/
├── config/codenarc/codenarc.groovy
├── src/
│   ├── main/groovy/com/example/inventory/
│   │   ├── App.groovy
│   │   ├── Item.groovy
│   │   └── InventoryService.groovy
│   ├── main/resources/
│   ├── test/groovy/com/example/inventory/
│   │   └── InventoryServiceSpec.groovy
│   └── test/resources/
└── README.md
  • Groovy and Java sources can live side by side; Gradle's groovy plugin compiles both together (joint compilation).
  • One class per file, with the package matching the folder, as in Java.

Code quality tools

// illustrative — build.gradle
plugins {
    id 'groovy'
    id 'codenarc'
    id 'jacoco'
}

codenarc {
    toolVersion = '3.7.0'
    configFile = file('config/codenarc/codenarc.groovy')
}

jacocoTestReport {
    reports { html.required = true }
}
  • CodeNarc — static analysis (unused imports, empty catch blocks, complexity, naming). Its rule sets are configured in a Groovy DSL.
  • JaCoCo — test coverage, works for Groovy bytecode.
  • GroovyDoc — ./gradlew groovydoc generates API documentation from /** */ comments.
  • Check exact plugin and tool versions against their documentation; the ones above are examples.

Packaging and running

./gradlew installDist      # build/install/inventory/bin/inventory (+ .bat)
./gradlew distZip          # a zip with start scripts and all jars
./gradlew jar              # just your classes; needs the Groovy jar at runtime

The application plugin produces start scripts plus every dependency, including the Groovy runtime — the simplest way to ship a command-line tool. For a single "fat" jar, use the Shadow plugin.

Containers

# illustrative — Dockerfile
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY build/install/inventory/ /app/
USER 10001
ENTRYPOINT ["/app/bin/inventory"]

Groovy applications deploy exactly like Java ones: same JVM, same container images, same monitoring. Tune the JVM (-Xmx, GC choice) through JAVA_OPTS as usual.

Versions and upgrades

  • Groovy's Maven coordinates changed in Groovy 4 from org.codehaus.groovy to org.apache.groovy.
  • Keep Groovy modules (groovy, groovy-json, ...) on the same version; the groovy-bom platform makes that easy.
  • Frameworks pin Groovy versions (Gradle bundles its own Groovy for build scripts; Jenkins pipelines use the Groovy inside Jenkins), so check which version a host runs before using new syntax.
  • Read the release notes' "breaking changes" section when upgrading a major version.