Build Tools
41.1 Gradle (Groovy DSL)
Gradle concepts: projects, tasks, plugins, configurations, the task graph, buildSrc / convention plugins, the settings.gradle multi-project setup, the configuration cache, incremental builds.
Writing Gradle plugins in Groovy (class MyPlugin implements Plugin<Project>). Note that the Kotlin DSL (build.gradle.kts) is now Gradle's default, but the Groovy DSL remains fully supported.
// build.gradle
plugins {
id 'groovy'
id 'application'
}
group = 'com.example'
version = '1.0.0'
repositories { mavenCentral() }
dependencies {
implementation 'org.apache.groovy:groovy:4.0.28' // Groovy 4+ coordinates: org.apache.groovy
implementation 'org.apache.groovy:groovy-json:4.0.28'
testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
java { toolchain { languageVersion = JavaLanguageVersion.of(21) } }
application { mainClass = 'com.example.App' }
tasks.named('test') { useJUnitPlatform() }
tasks.register('hello') {
group = 'custom'
doLast { println "Hello from Gradle ${gradle.gradleVersion}" }
}
compileGroovy {
groovyOptions.configurationScript = file('config/groovyc.groovy') // e.g., global CompileStatic
}41.2 Maven
Dependencies: org.apache.groovy:groovy (or groovy-all as a BOM/POM aggregate).
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>4.0.1</version>
<executions><execution><goals>
<goal>addSources</goal><goal>addTestSources</goal>
<goal>compile</goal><goal>compileTests</goal>
</goals></execution></executions>
</plugin>41.3 Grape and @Grab
Downloads are cached in ~/.groovy/grapes. Configure with ~/.groovy/grapeConfig.xml. grape install/list/resolve CLI.
@Grab('com.google.guava:guava:33.0.0-jre')
@Grab(group = 'org.apache.commons', module = 'commons-lang3', version = '3.14.0')
@GrabResolver(name = 'custom', root = 'https://repo.example.com/maven')
@GrabExclude('commons-logging:commons-logging')
import com.google.common.collect.ImmutableList
import org.apache.commons.lang3.StringUtils
println ImmutableList.of(1, 2, 3)
println StringUtils.reverse("groovy")