Not on the latest Gradle? The Gradle Security Subscription covers older versions under SLA. Learn more →

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.

build.gradle
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

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.