skip to content

Plugins

Applying plugins through the plugins {} block, managing their versions and resolution, the core plugin families, and where community plugins come from. Interviewers ask because plugins supply nearly all of a real build's behavior.

on this pageshow

explore

questions

72 · 3 sections

In a multi-project Gradle build, what does declaring a plugin with `apply false` in the root build script do, and why would you do it?

level: juniorimportance: must knowfreq 60%
basics
~10 s

apply false adds the plugin to the build's classpath and resolves its version, but does NOT apply (activate) it to the root project. Subprojects can then apply it by id with no version.

open as a page

What is the legacy apply(plugin = "...") syntax in Gradle, and how does it differ from the modern plugins {} DSL?

level: juniorimportance: must knowfreq 60%
basics
~20 s

apply(plugin = "...") is the old imperative way to apply a plugin by ID anywhere in the build script. The modern plugins {} DSL is a declarative block at the top that Gradle understands ahead of time.

open as a page

What is the plugins {} block in a Gradle build script, and how do you apply a core plugin and a community plugin with it?

level: juniorimportance: must knowfreq 78%
basics
~10 s

The plugins {} block is the declarative way to apply Gradle plugins. Use id("...") for a plugin, adding version "..." for community plugins. Core plugins like java need no version.

open as a page

How do you declare a plugin and its version in the plugins {} block, and where does Gradle resolve that plugin from?

level: juniorimportance: must knowfreq 75%
basics
~10 s

Use id("com.example.foo") version "1.2.3" inside plugins {}. Gradle resolves the plugin from the Gradle Plugin Portal (or repositories declared in settings' pluginManagement) by looking up its marker artifact.

open as a page

A teammate adds `id('org.jetbrains.kotlin.jvm') version '1.9.24'` (with the version) to two different subprojects' build scripts and the build fails. Why, and how does the `apply false` pattern fix it?

level: middleimportance: must knowfreq 50%
basics
~20 s

Requesting the same plugin version in two projects sharing a classpath conflicts. You fix it by requesting the version once at the root with apply false, then applying by id (no version) in each subproject.

open as a page

What is the pluginManagement {} block, and where must it appear in a Gradle build?

level: juniorimportance: must knowfreq 62%
basics
~10 s

pluginManagement {} is a block in settings.gradle.kts that configures where Gradle resolves plugins from (repositories) and how. It must be the first block in the settings file, before anything else.

open as a page

What is the Gradle Plugin Portal, and how does Gradle use it by default to resolve plugins applied via the plugins {} block?

level: juniorimportance: must knowfreq 62%
basics
~10 s

The Gradle Plugin Portal (plugins.gradle.org) is the public registry of community Gradle plugins. By default Gradle searches it via gradlePluginPortal() to resolve plugins declared by id in the plugins {} block.

open as a page

What is a Settings plugin in Gradle, and where do you apply one?

level: juniorimportance: must knowfreq 55%
basics
~10 s

A Settings plugin implements Plugin<Settings> and is applied in the plugins {} block of settings.gradle.kts. It runs during the settings phase, before any project is configured.

open as a page

Inside pluginManagement, how do you configure plugin repositories, and what is the default if you don't?

level: middleimportance: must knowfreq 55%
basics
~10 s

Add a repositories {} block inside pluginManagement {} and call helpers like gradlePluginPortal() and mavenCentral(). If you declare none, Gradle defaults to the Gradle Plugin Portal only.

open as a page

How do you configure Gradle to resolve internal/company plugins alongside the public Gradle Plugin Portal?

level: middleimportance: must knowfreq 55%
basics
~10 s

Add your internal Maven repository to pluginManagement.repositories in settings, and re-add gradlePluginPortal() so both public and internal plugins resolve. Order/strategy decides precedence.

open as a page

What lifecycle tasks does the Gradle 'base' plugin contribute, and what does each one mean?

level: juniorimportance: must knowfreq 70%
basics
~10 s

The base plugin adds 'assemble' (build all artifacts), 'check' (run all verification like tests), 'build' (assemble + check together), and 'clean' (delete the build directory).

open as a page

What does applying the core `java` plugin give you in a Gradle build?

level: juniorimportance: must knowfreq 78%
basics
~10 s

The java plugin adds the main and test source sets, compile tasks (compileJava, compileTestJava), processResources, the jar task, and the standard build/check/assemble lifecycle wiring.

open as a page

What does the `project-report` plugin add to a Gradle build, and which report tasks does it contribute?

level: juniorimportance: must knowfreq 45%
basics
~10 s

Applying project-report adds tasks that generate diagnostic reports: dependencyReport, taskReport, propertyReport, and the aggregate projectReport task, plus an HTML dependency report.

open as a page

What is a SourceSet in Gradle's Java plugin, and what two source sets does the plugin create by default?

level: juniorimportance: must knowfreq 70%
basics
~10 s

A SourceSet is a named group of source files compiled together. The java plugin creates two by default: main (production code) and test (test code that depends on main's output).

open as a page

You wrote a custom task that packages a distribution. How do you make `gradle build` run it, and where should it hook?

level: middleimportance: must knowfreq 55%
basics
~10 s

Make assemble depend on your packaging task: tasks.named("assemble") { dependsOn(myTask) }. Since build depends on assemble, gradle build will then run it.

open as a page