Java › Build Tools: Maven & Gradle
How does Gradle's build script (build.gradle / build.gradle.kts) differ structurally from Maven's declarative XML pom.xml?
IntermediateAnswer
Maven's pom.xml is a purely declarative XML document describing what the project needs (dependencies, plugins, configuration), with the actual build logic entirely hidden inside Maven's plugin implementations; Gradle's build.gradle (Groovy DSL) or build.gradle.kts (Kotlin DSL) is instead an actual executable script, giving you a full general-purpose programming language to express custom build logic directly, imperative task definitions, and conditional configuration -- this makes Gradle more flexible and often more concise for complex, non-standard build requirements, at the cost of build scripts potentially becoming harder to reason about if that flexibility gets over-used.
// build.gradle.kts (Kotlin DSL)
plugins {
id("java")
}
dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.2")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
}
tasks.test {
useJUnitPlatform()
}Real-world example A team needing a custom build step (generating a version file from git commit metadata before compilation) finds this straightforward to express as arbitrary Kotlin code directly in their build.gradle.kts, whereas achieving the same thing in Maven would require writing and configuring a full custom plugin due to pom.xml's purely declarative nature.