Gradle and Groovy
Write your build in Groovy with the Groovy DSL, and build Groovy applications, libraries and Gradle plugins with the Groovy plugin.
Write your build in Groovy
The Groovy DSL is Gradle's original build language, and builds written in build.gradle files are fully supported.
One build can mix Groovy and Kotlin build scripts, so you can move to the Kotlin DSL one project at a time.
New builds use the Kotlin DSL by default since Gradle 8.2. To start a build in Groovy, pass --dsl groovy to gradle init.
plugins {
id 'groovy'
id 'application'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.apache.groovy:groovy:6.0.1'
testImplementation 'org.spockframework:spock-core:2.5-groovy-6.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
application {
mainClass = 'com.example.App'
}
tasks.named('test') {
useJUnitPlatform()
}Build Groovy projects
The Groovy plugin adds Groovy compilation to the Java plugin. Apache Groovy and Java code can live in the same project.
-
Applications and libraries
Compile Groovy, and Groovy and Java together with joint compilation, for applications and libraries.
The Groovy plugin → -
Testing with Spock
Write specifications with the Spock Framework and run them on the JUnit Platform.
Spock Framework → -
Gradle plugins
Share build logic as precompiled script plugins written in Groovy.
Precompiled script plugins →
Keep your Groovy builds healthy
-
Make builds fast
Turn on the build cache and the configuration cache. Groovy compilation is cacheable, so unchanged code isn't compiled again.
-
Organize your sources
Follow the best practices for organizing Gradle projects, so your build is easy to navigate and Gradle does less work.
-
Explore your build
Why is my Groovy code recompiled when nothing changed? Where do these deprecation warnings come from? A Build Scan answers both.
-
Get help
Search the docs and the forums from the help page, or ask in the Gradle Forums.
Start a Groovy project
Run gradle init --type groovy-application --dsl groovy to create a Groovy build with the Groovy DSL, Spock tests and the Gradle Wrapper.