skip to content

What does the pluginManagement block look like in the Groovy DSL versus the Kotlin DSL, and what syntactic differences should you watch for?

level: juniorimportance: should knowfreq 30%

answer

  1. same block, different syntax
  2. Groovy: single quotes, no parens
  3. Kotlin: double quotes, parens, url = uri()
  4. .gradle vs .gradle.kts
  5. Kotlin = type-safe + autocomplete

basics

~10 s

Both have the same block in settings. Groovy (settings.gradle) uses id 'x' version '1.0' with single quotes; Kotlin (settings.gradle.kts) uses id("x") version "1.0" with parentheses and double quotes.

solid answer

~30 s

`pluginManagement {}` exists identically in both DSLs and goes at the top of the settings file. The differences are purely syntactic. In the **Groovy DSL** (`settings.gradle`) you use space-call syntax and single quotes: `id 'org.x' version '1.0'`, `maven { url 'https://...' }`. In the **Kotlin DSL** (`settings.gradle.kts`) everything is statically typed and explicit: `id("org.x") version "1.0"`, `maven { url = uri("https://...") }`, and you call factory methods like `gradlePluginPortal()` with parentheses. The Kotlin DSL gives IDE autocomplete and type checking; the Groovy DSL is terser. The structure and semantics of the block are the same — only the surface syntax differs.

code

groovy · 10 lines
groovy
// settings.gradle (Groovy)
pluginManagement {
    repositories {
        gradlePluginPortal()
        maven { url 'https://nexus.corp/plugins' }
    }
    plugins {
        id 'org.jetbrains.kotlin.jvm' version '2.0.20'
    }
}

go deeper

for a junior

Recognize both forms and translate the quoting/parentheses correctly.

for a middle

Explain the type-safety benefit of Kotlin DSL and the common porting pitfalls (url = uri).

for a senior

Advise on choosing one DSL consistently and migrating, weighing tooling vs. team familiarity.

for a principal

Standardize DSL choice across the org's repos and define a migration approach for legacy Groovy builds.

## Same block, two languages Gradle build/settings scripts can be written in **Groovy** (`.gradle`) or **Kotlin** (`.gradle.kts`). The `pluginManagement {}` block is available in both and means exactly the same thing. Choosing a DSL is a project-wide decision; you only need to translate the syntax. ## Groovy DSL — settings.gradle ```groovy pluginManagement { repositories { gradlePluginPortal() maven { url 'https://nexus.corp/plugins' } } plugins { id 'org.jetbrains.kotlin.jvm' version '2.0.20' } } ``` Notes: - Single quotes for strings (double quotes are GStrings/interpolation). - Method calls without parentheses are common: `url '...'`. - Dynamic typing — typos surface at runtime. ## Kotlin DSL — settings.gradle.kts ```kotlin pluginManagement { repositories { gradlePluginPortal() maven { url = uri("https://nexus.corp/plugins") } } plugins { id("org.jetbrains.kotlin.jvm") version "2.0.20" } } ``` Notes: - Double quotes for strings. - Explicit parentheses: `id("...")`, `gradlePluginPortal()`. - `url` is an assignable property: `url = uri("...")` (not `url "..."`). - Static typing → IDE autocomplete, compile-time checks, easier refactoring. ## Common porting mistakes - Forgetting `url = uri(...)` in Kotlin and writing `url("...")` or `url "..."`. - Using single quotes in Kotlin (Kotlin chars are single-quoted, strings are double). - Dropping parentheses on factory methods in Kotlin. ## Which to pick New projects commonly choose the Kotlin DSL for tooling support; many existing builds remain on Groovy. The pluginManagement structural rules (first block, sub-blocks) are identical regardless.

  • In the Kotlin DSL, how do you set a custom maven repository URL inside pluginManagement?
    maven { url = uri("https://...") } — url is an assignable property and the value is wrapped with uri().
  • Do the structural rules (block must be first) differ between the two DSLs?
    No. The first-block requirement and available sub-blocks are identical; only string/call syntax changes.

saying these in an interview costs you the question

  • Saying the Kotlin and Groovy versions behave differently semantically
  • Using url '...' (space-call) in Kotlin
  • Single-quoting strings in Kotlin scripts

context