skip to content

Gradle

Gradle's model: a programmable build in Groovy or Kotlin, a task DAG, configurations for dependencies, plugins, and aggressive incrementality and caching. Interviewers ask because Gradle rewards people who understand its lifecycle and punishes those who only copy snippets.

on this pageshow

explore

questions

1,413 · 13 sections

What is the buildscript {} block in a Gradle build script, and what goes inside it?

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

buildscript {} configures the build script itself: it declares repositories {} and dependencies { classpath(...) } that put plugin and helper jars on the classpath the script needs to compile and run.

open as a page

Why must the plugins {} block appear first in a build.gradle(.kts) file, and what happens if you put code before it?

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

The plugins {} block must be the first statement (after any buildscript/pluginManagement). Gradle parses it specially and early to resolve plugins. Putting other code before it causes a build failure.

open as a page

What is the dependencyResolutionManagement {} block, and which Gradle build file does it belong in?

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

It is a block in settings.gradle(.kts) — not build.gradle — where you centrally declare repositories and version catalogs for the whole build instead of repeating them in each module.

open as a page

What is a Gradle extension, and how does adding one give a plugin its own configuration block in the build script?

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

An extension is an object a plugin registers via project.extensions.create("name", Type::class.java). Gradle then exposes a build-script block named after it (e.g. name { ... }) that configures that object.

open as a page

What are Gradle's extra (ext) properties, and how do you declare and read them in a build script?

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

Extra properties are arbitrary user-defined key/value pairs attached to a Gradle object. You set them with ext { key = value } (Groovy) or by extra (Kotlin) and read them back by name later in the script.

open as a page

In a Gradle task definition, what is the difference between code in the configuration block and code inside doFirst{}/doLast{}, and when does each run?

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

Configuration-block code runs during the configuration phase for every build invocation. doFirst{}/doLast{} are action closures that run only in the execution phase, and only if the task actually executes.

open as a page

What does task.onlyIf {} do in Gradle, and what happens to a task whose onlyIf predicate returns false?

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

onlyIf {} attaches a predicate evaluated right before the task runs. If it returns false, Gradle skips the task's actions and reports it as SKIPPED. If true (or absent), the task executes normally.

open as a page

What is the difference between the tasks a user requested on the command line and the tasks Gradle actually schedules and executes?

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

Requested tasks are the names you type on the command line (e.g. gradle build). Executed tasks are those plus all their dependencies, which Gradle computes and runs in dependency order.

open as a page

What is gradle.taskGraph.whenReady{} and when does the closure it registers actually run?

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

whenReady registers a callback that runs once Gradle has finished building the task execution graph for the build, after configuration but before any task executes.

open as a page

What does the Gradle `init` task do, and how do you use it to scaffold a new project?

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

gradle init is a built-in task from the build-init plugin that scaffolds a new Gradle project: it generates build/settings scripts, a sample source layout, and the Gradle wrapper, prompting you (or via flags) for project type, DSL, and test framework.

open as a page

You try to resolve `implementation` and get an error that it cannot be resolved. Why, and what should you resolve instead?

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

implementation is a declaration bucket — isCanBeResolved is false — so it has no resolution result. Resolve compileClasspath or runtimeClasspath, which extend from it.

open as a page

What is the `dependencies {}` block in a Gradle build script, and how do you add a dependency to a specific configuration inside it?

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

The dependencies {} block is where you declare a module's dependencies. Inside it you call a configuration name like implementation(...) with the dependency coordinates (group:name:version) to attach a dependency to that configuration.

open as a page

How do `testImplementation` and `testRuntimeOnly` relate to the main source set's configurations, and when do you use each?

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

testImplementation adds a dependency to the test compile + runtime classpath (e.g. JUnit, Mockito). testRuntimeOnly adds it only to the test runtime classpath (e.g. the JUnit Platform launcher engine). Test classpaths also extend the main ones.

open as a page

How do you exclude a single transitive dependency that is pulled in by one specific dependency in Gradle?

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

Attach an exclude block to that one dependency, naming the unwanted artifact by group and/or module. Only that dependency's transitive graph is affected.

open as a page

What does the string dependency notation 'group:name:version' mean in Gradle, and how do you declare such a dependency?

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

It's the shorthand for a module's coordinates: group (org), name (artifact), version. You declare it inside a configuration, e.g. implementation("org.apache.commons:commons-lang3:3.14.0").

open as a page

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

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

In a Gradle composite build, what happens to a dependency on a published module when you include the producing build with includeBuild?

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

Gradle automatically substitutes the published module coordinates with the local included build's project. Instead of downloading the artifact from a repository, it builds and uses the local source.

open as a page

What is a composite build in Gradle, and how do you wire one using includeBuild?

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

A composite build combines otherwise independent Gradle builds into one. You wire it by adding includeBuild('../other-build') to settings.gradle.kts; Gradle then treats the included build as part of the current build.

open as a page

What must the in-development plugin build declare so that a consumer including it can apply the plugin by its id?

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

The plugin build must apply the java-gradle-plugin plugin and declare the plugin id and implementationClass in a gradlePlugin { plugins { register(...) } } block. That generates the marker the consumer's id resolves against.

open as a page

How do you run a task that lives in an included build from the command line in a Gradle composite build?

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

Prefix the task path with the included build's name: ./gradlew :includedBuildName:some:task. The leading segment is the build name (its directory name unless overridden), not a project in the root build.

open as a page

In a Gradle multi-project build, how do you make one subproject depend on another subproject so it can use its classes and outputs?

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

Add a project dependency in the consumer's build file, e.g. implementation(project(":lib")). Gradle builds :lib first and puts its compiled output and dependencies on the consumer's classpath.

open as a page

What does it mean for a Gradle task to be cacheable, and what is the minimum required to make a task's outputs reusable from the build cache?

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

A cacheable task can store its outputs in the build cache and restore them later instead of re-running. It needs the @CacheableTask annotation and fully declared inputs and outputs.

open as a page

How do you turn the Gradle build cache on, and what is the simplest way to make it the default for everyone on the project?

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

Set org.gradle.caching=true in the project's gradle.properties so it is on for every build and every developer, or pass --build-cache on a single command to enable it just for that run.

open as a page

When you run a Gradle build, what does the FROM-CACHE outcome next to a task mean, and how does it differ from UP-TO-DATE and executed?

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

FROM-CACHE means Gradle restored the task's outputs from the build cache instead of running it. UP-TO-DATE means outputs were already on disk and unchanged. Executed means the task actually ran.

open as a page

Where does Gradle's local build cache store its entries by default, and what does it actually hold?

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

By default the local build cache lives in ~/.gradle/caches/build-cache-1. It stores the outputs of cacheable tasks keyed by a hash, so a later build can reuse them instead of re-running the task.

open as a page

Where in a Gradle project do you configure the push/pull split for the remote build cache, and at what point in the build lifecycle does that configuration take effect?

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

In settings.gradle(.kts), inside the buildCache { remote<HttpBuildCache> { ... } } block. It takes effect very early — during settings evaluation, before any project is configured — because the cache must be ready before tasks run.

open as a page

What is Gradle's continuous build (-t/--continuous), and how does it differ from running a task once?

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

Continuous build runs gradle -t <task> (or --continuous). Gradle stays alive, watches the task inputs, and automatically re-runs the requested tasks whenever a relevant input file changes, instead of exiting after one run.

open as a page

What does the built-in `dependencies` task do, and how do you scope it to a single configuration?

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

gradle dependencies prints the resolved dependency trees for each configuration. Use --configuration <name> (e.g. runtimeClasspath) to limit the output to one configuration instead of dumping every one.

open as a page

How do you exclude a specific task from a Gradle build invocation, and what exactly does excluding it do to its dependencies?

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

Use -x or --exclude-task with the task name, e.g. gradle build -x test. Gradle removes that task — and any task needed only by it — from the execution graph for this run.

open as a page

Which command-line flags control Gradle's log verbosity, and how do they relate to one another?

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

Use --quiet (-q) for less output, --info (-i) for more, and --debug (-d) for everything. They set the log level; only one applies, with --debug the most verbose and --quiet the least.

open as a page

What is the difference between passing -Pname=value and -Dname=value on the Gradle command line?

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

-P sets a Gradle project property, read via project.property("name"). -D sets a JVM system property, read via System.getProperty("name"). -P is Gradle-specific; -D is standard JVM.

open as a page

What is the Gradle Worker API, and why would a custom task use it instead of just running its work directly in the task action?

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

The Worker API lets a task hand units of work to Gradle's worker pool so they run in parallel. You inject WorkerExecutor, define a WorkAction, and submit work to a queue. It enables parallelism and isolation that a plain task action can't get.

open as a page

What does Property.convention(...) do on a Gradle lazy property, and how does it differ from calling set(...)?

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

convention(...) supplies a default value used only if nobody calls set(...). set(...) is an explicit assignment that overrides any convention. So convention = fallback default, set = the actual chosen value.

open as a page

What is a Gradle DSL extension, and how do you register one from a plugin so users can configure your plugin in their build script?

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

An extension is an object added to a project that exposes a configuration block (DSL). A plugin registers it with project.extensions.create("myExt", MyExtension::class.java), then users configure it via a myExt { ... } block.

open as a page

What is a NamedDomainObjectContainer in Gradle, and why would a plugin author expose one in their extension?

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

It's a Gradle collection of objects each identified by a unique name. Plugins expose one so users can declare multiple named instances in a DSL block, like sourceSets or configurations.

open as a page

Your plugin defines an extension with a `Property<String>` called `greeting`. How do you connect that extension value to a task's input property so the task uses whatever the user sets in the build script?

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

Use task.greeting.set(extension.greeting). This wires the task's Property to the extension's Property lazily, so the value is read later (at execution), not while configuring.

open as a page

How do you enable JaCoCo code-coverage reporting in a Gradle build, and what does applying the jacoco plugin give you?

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

Add jacoco to the plugins {} block. Gradle then adds a jacocoTestReport task and a jacoco {} extension, and instruments your tests so coverage data is collected when you run test.

open as a page

What is Gradle TestKit's GradleRunner, and how do you use it to functionally test a Gradle plugin?

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

GradleRunner is the TestKit entry point that runs a real Gradle build against a temporary project directory. You create it, point it at a project dir, pass arguments, and call build() to execute and inspect the result.

open as a page

What does the jacocoTestCoverageVerification task do in a Gradle build, and how do you make it fail the build when coverage drops below a threshold?

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

It's a JaCoCo plugin task that checks coverage against rules you define in violationRules. If coverage is below the configured minimum, the task fails, which fails the build.

open as a page

What is the JUnit BOM and why would you use `testImplementation(platform("org.junit:junit-bom:..."))` in a Gradle build instead of pinning each JUnit artifact's version individually?

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

The JUnit BOM is a Bill of Materials that declares one consistent version for all JUnit modules (Jupiter, Platform, Vintage). Importing it with platform(...) lets you list JUnit dependencies without versions, so they all align.

open as a page

How do you tell Gradle's Test task to run JUnit 5 (Jupiter) tests instead of the default JUnit 4 runner?

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

Call useJUnitPlatform() on the test task. By default Gradle uses the JUnit 4 runner, so you must opt into the JUnit Platform for Jupiter tests to be detected and executed.

open as a page

How do the archiveBaseName, archiveVersion, and archiveClassifier properties on an archive task (like Jar) combine to form the final published artifact file name?

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

Gradle assembles the name as [baseName]-[appendix]-[version]-[classifier].[extension]. So baseName 'app', version '1.0', classifier 'sources' produces app-1.0-sources.jar. Empty parts are skipped along with their dash.

open as a page

Where in the build script do you attach a custom artifact, and what's the minimal correct snippet to add a fat JAR to a Maven publication?

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

Inside publishing { publications { ... } }, on the publication, call artifact(tasks.named("fatJar")). That single line adds the fat JAR as an extra file on that publication's coordinates.

open as a page

How do you make a Gradle Java library publish a sources jar and a javadoc jar alongside the main artifact?

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

Inside the java { } block call withSourcesJar() and withJavadocJar(). Gradle registers sourcesJar and javadocJar tasks and attaches them to the java component, so they publish automatically.

open as a page

What is the Gradle Module Metadata (the `.module` file), and what does it describe that a traditional Maven POM cannot?

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

It's a JSON file (module.module) Gradle publishes alongside the POM. It describes a module's variants, their dependencies, and attributes — richer info than a flat POM can express, so Gradle can pick the right variant when resolving.

open as a page

What is a SoftwareComponent in Gradle, and how does it relate to what gets published?

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

A SoftwareComponent describes what a project produces for publication (its artifacts and dependencies). The MavenPublication's from(components.java) reads a component to populate the artifacts and POM/metadata that get published.

open as a page

What does the Gradle daemon do, and how do you disable it for a single build invocation?

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

The daemon is a long-lived background JVM that Gradle reuses across builds to avoid startup cost. Disable it for one build with --no-daemon, or permanently via org.gradle.daemon=false in gradle.properties.

open as a page

What does the org.gradle.daemon.idletimeout property control, and what is its default?

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

It sets how long (in milliseconds) an idle Gradle daemon stays alive before shutting itself down. The default is 10800000 ms — three hours.

open as a page

What is org.gradle.jvmargs and where do you set it to control the Gradle daemon's heap?

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

org.gradle.jvmargs is a Gradle property that passes JVM flags (like -Xmx) to the build daemon's JVM. You set it in gradle.properties, usually in the project root or the user's ~/.gradle directory.

open as a page

What is the difference between the JVM that runs the Gradle daemon and the JVM used by Java toolchains for compiling and testing your code?

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

The daemon JVM is the JVM that actually runs Gradle itself. Java toolchains pick a (possibly different) JDK to compile and run your project's code. They are configured separately and can be different versions.

open as a page

Where can a gradle.properties file live, and what is each location used for?

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

Two main spots: the project root (<project>/gradle.properties), checked into the repo for shared settings, and GRADLE_USER_HOME (~/.gradle/gradle.properties), a per-developer/machine file for local or secret values.

open as a page

What does applying the 'eclipse' plugin to a Gradle build give you, and which files does it generate?

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

Applying eclipse adds tasks that generate Eclipse metadata files: .project and .classpath (and .settings). You run ./gradlew eclipse to create them and cleanEclipse to remove them.

open as a page

What actually happens when your IDE runs a 'Gradle sync', and why can it take much longer than just opening files?

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

Sync runs the build's initialization and configuration phases through Gradle's Tooling API to discover projects, tasks, dependencies and source sets, then feeds that model to the IDE. It does not run your tasks, but it does execute build-script code.

open as a page

What are Gradle's console output modes (--console=plain/rich/auto), and what does each one do?

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

Gradle has three console modes. plain gives flat text with no colors or progress bar. rich forces colors and the animated progress bar. auto (the default) picks rich when attached to a terminal, plain otherwise.

open as a page

Walk me through the CLI flags that change Gradle's log verbosity and what each one does.

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

-q/--quiet shows only errors and important messages; -i/--info adds informational detail like up-to-date reasons; -d/--debug shows everything including internals and timestamps. No flag means the default LIFECYCLE level.

open as a page

What is Gradle's default log level when you run a build, and what kind of output does it show?

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

The default level is LIFECYCLE. It shows task execution progress, the BUILD SUCCESSFUL/FAILED line, and user-facing messages — but hides INFO and DEBUG detail to keep output concise.

open as a page

What is the android { } DSL block, and what is its role once AGP is applied?

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

android { } is the configuration extension AGP registers when you apply it. Inside it you set things like compileSdk, namespace, and defaultConfig. It configures AGP's tasks; without AGP applied, the block does not exist.

open as a page

What is the Android Gradle Plugin (AGP), and how does it relate to Gradle itself?

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

AGP is a Gradle plugin you apply with com.android.application (or com.android.library). Gradle is the generic build engine; AGP teaches Gradle how to build an Android app — compile, package an APK/AAB, and run Android-specific tasks.

open as a page

What are build types in the Android Gradle Plugin (AGP), and what do the default `debug` and `release` build types represent?

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

Build types are AGP configurations for how an app is built. AGP ships two by default: debug (debuggable, no shrinking) and release (optimizable, shrinkable, signable for distribution).

open as a page

What is the Jib Gradle plugin and how does it build a container image differently from a typical Dockerfile-based build?

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

Jib is a Gradle plugin (com.google.cloud.tools.jib) that builds an OCI/Docker image for a JVM app directly from your build, with no Dockerfile and no Docker daemon. You run a task like jib or jibDockerBuild.

open as a page

What is the Kotlin Multiplatform Gradle plugin, and how do you declare the platforms a module should compile for?

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

Apply the org.jetbrains.kotlin.multiplatform plugin, then open a kotlin { } block and call target functions like jvm(), js(), and iosX64(). Each call adds a platform the module compiles for.

open as a page