# Groovy — Powerful Multi-Faceted JVM Language for Scripting and Beyond > Apache Groovy is a dynamic and optionally typed language for the JVM that integrates seamlessly with Java, powering Gradle builds, Jenkins pipelines, and rapid application development. ## Install Save in your project root: # Groovy — Powerful Multi-Faceted JVM Language for Scripting and Beyond ## Quick Use ```bash # Install Groovy via SDKMAN curl -s https://get.sdkman.io | bash sdk install groovy # Hello world echo 'println "Hello, Groovy!"' > hello.groovy groovy hello.groovy # Or use the Groovy shell groovysh ``` ## Introduction Apache Groovy is a dynamic, optionally typed programming language for the Java Virtual Machine. It combines scripting convenience with enterprise-strength features, serving as both a standalone language and a scripting layer for Java applications. Groovy is the language behind Gradle build scripts, Jenkins Pipeline DSLs, and Grails web applications. ## What Groovy Does - Runs on the JVM with full interoperability with Java classes and libraries - Supports both dynamic and static typing with optional type checking - Provides concise syntax for closures, builders, and DSL creation - Powers Gradle, the build system used by Android and many Java projects - Offers a scripting mode for quick automation without compilation ## Architecture Overview Groovy compiles to JVM bytecode, either ahead of time via `groovyc` or dynamically at runtime. The compiler supports two modes: dynamic (default) with runtime dispatch via the Meta-Object Protocol, and static compilation (`@CompileStatic`) that produces performance close to Java. The MOP enables runtime metaprogramming, mixins, and method interception. ## Self-Hosting & Configuration - Install via SDKMAN, Homebrew, or download from groovy-lang.org - Run scripts directly with `groovy script.groovy` without a compile step - Use Grape annotations (`@Grab`) to pull Maven dependencies inline - Configure static compilation per class with `@CompileStatic` or `@TypeChecked` - Integrate into Maven or Gradle builds via the Groovy compiler plugin ## Key Features - Seamless Java interop: call any Java library without wrappers - Closures, operator overloading, and builder pattern for expressive DSLs - GStrings (interpolated strings) and multi-line string literals - Built-in JSON, XML, and YAML parsing and generation - Spock testing framework for highly readable BDD-style tests ## Comparison with Similar Tools - **Java** — Java is more verbose; Groovy adds concise syntax, closures, and scripting capabilities on the same JVM - **Kotlin** — Kotlin is statically typed with modern features; Groovy offers dynamic typing and stronger metaprogramming - **Scala** — Scala has a more complex type system; Groovy prioritizes simplicity and Java familiarity - **Python** — Python is not JVM-native; Groovy provides similar scripting feel with full Java ecosystem access - **Clojure** — Clojure is a functional Lisp on the JVM; Groovy is imperative/OOP with optional functional features ## FAQ **Q: Is Groovy slower than Java?** A: Dynamic Groovy has overhead from runtime dispatch. Using `@CompileStatic` produces bytecode with performance comparable to Java. **Q: What is the relationship between Groovy and Gradle?** A: Gradle uses Groovy (or Kotlin) as its build script DSL. Groovy's closure syntax and builder pattern make it well-suited for declarative build definitions. **Q: Can I use Groovy in existing Java projects?** A: Yes. Groovy classes compile to standard JVM bytecode and can be mixed freely with Java code in the same project. **Q: Is Groovy still actively maintained?** A: Yes. Apache Groovy has regular releases (4.x series) and is maintained by the Apache Software Foundation. ## Sources - https://github.com/apache/groovy - https://groovy-lang.org/documentation.html --- Source: https://tokrepo.com/en/workflows/asset-5ab4ef3e Author: AI Open Source