Plugins are how Gradle supports Kotlin, Android, Spring Boot, code quality and publishing.
Gradle itself is small; plugins add tasks, configurations and conventions. Apply them in the plugins { } block, which must be the first block in the script:
plugins {
java // core plugin, no version
id("org.springframework.boot") version "3.4.4"
kotlin("jvm") version "2.1.20"
}Core plugins (java, java-library, application, maven-publish, jacoco) are bundled. Community plugins are resolved from the Gradle Plugin Portal by default, or from repositories listed in pluginManagement { repositories { } } in settings.gradle.kts. Versions are pinned there or in the version catalog; in a multi-project build, declare a plugin version once (often apply false in the root) and apply it without a version in subprojects.
What plugins give you:
java-libraryaddsapiand ABI-aware compile avoidance.applicationaddsrunandinstallDistwith start scripts.org.springframework.bootaddsbootRunandbootJar.com.android.applicationturns a project into an Android app.jacoco,checkstyle,spotlessfor coverage and style.
Each plugin has an extension for configuration (java { }, application { }, springBoot { }). Prefer plugins { } over the legacy apply(plugin = ...), which doesn't support type-safe accessors. You can write your own convention plugins in buildSrc or an included build (Advanced).
Example
// settings.gradle.kts
pluginManagement {
repositories { gradlePluginPortal(); google(); mavenCentral() }
}
rootProject.name = "shop"
// build.gradle.kts
plugins {
`java-library`
application
jacoco
id("org.springframework.boot") version "3.4.4"
id("io.spring.dependency-management") version "1.1.7"
}
repositories { mavenCentral() }
application { mainClass = "com.acme.ShopApplication" }
jacoco { toolVersion = "0.8.12" }
tasks.jacocoTestReport { dependsOn(tasks.test); reports { html.required = true } }
// $ ./gradlew tasks -> now lists bootRun, bootJar, jacocoTestReport, run, installDistRemember
- plugins { } must come first; community plugins need a version
- Core plugins are bundled; others come from the Plugin Portal or configured repositories
- Each plugin adds tasks and an extension block to configure it
- Pin plugin versions once per build