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 pageshowhide
explore
- Build Scripts and DSL85 questions
- DSL Languages30 questions
- Script File Types30 questions
- Script Building Blocks25 questions
- Tasks and Task Graph103 questions
- Task Declaration & Registration36 questions
- Task Dependencies & Ordering27 questions
- Inputs, Outputs & Up-to-Date20 questions
- Task Actions & Graph API20 questions
- Dependency Management179 questions
- Declaring Dependencies30 questions
- Versions and Catalogs36 questions
- Resolution and Conflicts41 questions
- Repositories and Metadata42 questions
- Artifact Transforms10 questions
- Verification and Integrity20 questions
- Plugins72 questions
- Applying Plugins31 questions
- Plugin Management21 questions
- Core Plugin Families20 questions
- Multi-Project Builds100 questions
- Project Structure & Layout30 questions
- Cross-Project Dependencies20 questions
- Shared Configuration30 questions
- Composite Builds20 questions
- Build Cache and Performance146 questions
- Incremental Work Avoidance25 questions
- Build Cache30 questions
- Configuration Cache30 questions
- Parallelism And Daemon Performance35 questions
- Measurement And Profiling26 questions
- Lifecycle and Execution Model93 questions
- Build Lifecycle Phases27 questions
- Lifecycle Hooks and Listeners20 questions
- Command-Line Invocation31 questions
- Daemon Invocation15 questions
- Authoring Plugins, Tasks and Extensions186 questions
- Testing Integration111 questions
- The Test Task25 questions
- JVM Test Suites25 questions
- Framework Wiring20 questions
- Selection & Reporting20 questions
- Coverage & Plugin Testing21 questions
- Publishing and Artifacts95 questions
- Publication Models25 questions
- Components and Variants30 questions
- Repositories and Credentials25 questions
- Signing15 questions
- Wrapper, Distribution and Build Environment115 questions
- Wrapper & Distribution25 questions
- Version Management15 questions
- JVM Toolchains35 questions
- Properties & Environment20 questions
- Daemon JVM Tuning20 questions
- Tooling and IDE Integration66 questions
- Tooling API26 questions
- IDE Integration20 questions
- Logging and Console20 questions
- Ecosystem and Interop62 questions
- JVM Packaging Plugins31 questions
- Ecosystem Plugins Overview31 questions
questions
1,413 · 13 sectionsWhat is the buildscript {} block in a Gradle build script, and what goes inside it?
basics
~10 sbuildscript {} 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.
Why must the plugins {} block appear first in a build.gradle(.kts) file, and what happens if you put code before it?
basics
~10 sThe 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.
What is the dependencyResolutionManagement {} block, and which Gradle build file does it belong in?
basics
~10 sIt 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.
What is a Gradle extension, and how does adding one give a plugin its own configuration block in the build script?
basics
~10 sAn 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.
What are Gradle's extra (ext) properties, and how do you declare and read them in a build script?
basics
~20 sExtra 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.
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?
basics
~10 sConfiguration-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.
What does task.onlyIf {} do in Gradle, and what happens to a task whose onlyIf predicate returns false?
basics
~10 sonlyIf {} 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.
What is the difference between the tasks a user requested on the command line and the tasks Gradle actually schedules and executes?
basics
~10 sRequested 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.
What is gradle.taskGraph.whenReady{} and when does the closure it registers actually run?
basics
~10 swhenReady registers a callback that runs once Gradle has finished building the task execution graph for the build, after configuration but before any task executes.
What does the Gradle `init` task do, and how do you use it to scaffold a new project?
basics
~20 sgradle 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.
You try to resolve `implementation` and get an error that it cannot be resolved. Why, and what should you resolve instead?
basics
~10 simplementation is a declaration bucket — isCanBeResolved is false — so it has no resolution result. Resolve compileClasspath or runtimeClasspath, which extend from it.
What is the `dependencies {}` block in a Gradle build script, and how do you add a dependency to a specific configuration inside it?
basics
~10 sThe 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.
How do `testImplementation` and `testRuntimeOnly` relate to the main source set's configurations, and when do you use each?
basics
~20 stestImplementation 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.
How do you exclude a single transitive dependency that is pulled in by one specific dependency in Gradle?
basics
~10 sAttach an exclude block to that one dependency, naming the unwanted artifact by group and/or module. Only that dependency's transitive graph is affected.
What does the string dependency notation 'group:name:version' mean in Gradle, and how do you declare such a dependency?
basics
~10 sIt'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").
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?
basics
~10 sapply 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.
What is the legacy apply(plugin = "...") syntax in Gradle, and how does it differ from the modern plugins {} DSL?
basics
~20 sapply(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.
What is the plugins {} block in a Gradle build script, and how do you apply a core plugin and a community plugin with it?
basics
~10 sThe 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.
How do you declare a plugin and its version in the plugins {} block, and where does Gradle resolve that plugin from?
basics
~10 sUse 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.
What lifecycle tasks does the Gradle 'base' plugin contribute, and what does each one mean?
basics
~10 sThe base plugin adds 'assemble' (build all artifacts), 'check' (run all verification like tests), 'build' (assemble + check together), and 'clean' (delete the build directory).
In a Gradle composite build, what happens to a dependency on a published module when you include the producing build with includeBuild?
basics
~10 sGradle 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.
What is a composite build in Gradle, and how do you wire one using includeBuild?
basics
~10 sA 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.
What must the in-development plugin build declare so that a consumer including it can apply the plugin by its id?
basics
~10 sThe 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.
How do you run a task that lives in an included build from the command line in a Gradle composite build?
basics
~10 sPrefix 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.
In a Gradle multi-project build, how do you make one subproject depend on another subproject so it can use its classes and outputs?
basics
~10 sAdd 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.
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?
basics
~10 sA 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.
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?
basics
~10 sSet 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.
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?
basics
~10 sFROM-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.
Where does Gradle's local build cache store its entries by default, and what does it actually hold?
basics
~10 sBy 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.
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?
basics
~20 sIn 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.
What is Gradle's continuous build (-t/--continuous), and how does it differ from running a task once?
basics
~10 sContinuous 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.
What does the built-in `dependencies` task do, and how do you scope it to a single configuration?
basics
~10 sgradle 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.
How do you exclude a specific task from a Gradle build invocation, and what exactly does excluding it do to its dependencies?
basics
~10 sUse -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.
Which command-line flags control Gradle's log verbosity, and how do they relate to one another?
basics
~10 sUse --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.
What is the difference between passing -Pname=value and -Dname=value on the Gradle command line?
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.
How do you enable JaCoCo code-coverage reporting in a Gradle build, and what does applying the jacoco plugin give you?
basics
~10 sAdd 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.
What is Gradle TestKit's GradleRunner, and how do you use it to functionally test a Gradle plugin?
basics
~20 sGradleRunner 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.
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?
basics
~10 sIt'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.
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?
basics
~20 sThe 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.
How do you tell Gradle's Test task to run JUnit 5 (Jupiter) tests instead of the default JUnit 4 runner?
basics
~10 sCall 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.
How do the archiveBaseName, archiveVersion, and archiveClassifier properties on an archive task (like Jar) combine to form the final published artifact file name?
basics
~10 sGradle 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.
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?
basics
~10 sInside 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.
How do you make a Gradle Java library publish a sources jar and a javadoc jar alongside the main artifact?
basics
~10 sInside the java { } block call withSourcesJar() and withJavadocJar(). Gradle registers sourcesJar and javadocJar tasks and attaches them to the java component, so they publish automatically.
What is the Gradle Module Metadata (the `.module` file), and what does it describe that a traditional Maven POM cannot?
basics
~20 sIt'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.
What is a SoftwareComponent in Gradle, and how does it relate to what gets published?
basics
~10 sA 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.
Wrapper, Distribution and Build Environment
all 115 Wrapper, Distribution and Build Environment questions →What does the Gradle daemon do, and how do you disable it for a single build invocation?
basics
~10 sThe 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.
What does the org.gradle.daemon.idletimeout property control, and what is its default?
basics
~10 sIt sets how long (in milliseconds) an idle Gradle daemon stays alive before shutting itself down. The default is 10800000 ms — three hours.
What is org.gradle.jvmargs and where do you set it to control the Gradle daemon's heap?
basics
~10 sorg.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.
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?
basics
~10 sThe 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.
Where can a gradle.properties file live, and what is each location used for?
basics
~10 sTwo 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.
What does applying the 'eclipse' plugin to a Gradle build give you, and which files does it generate?
basics
~10 sApplying 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.
What actually happens when your IDE runs a 'Gradle sync', and why can it take much longer than just opening files?
basics
~20 sSync 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.
What are Gradle's console output modes (--console=plain/rich/auto), and what does each one do?
basics
~20 sGradle 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.
Walk me through the CLI flags that change Gradle's log verbosity and what each one does.
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.
What is Gradle's default log level when you run a build, and what kind of output does it show?
basics
~10 sThe 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.
What is the android { } DSL block, and what is its role once AGP is applied?
basics
~20 sandroid { } 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.
What is the Android Gradle Plugin (AGP), and how does it relate to Gradle itself?
basics
~20 sAGP 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.
What are build types in the Android Gradle Plugin (AGP), and what do the default `debug` and `release` build types represent?
basics
~10 sBuild 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).
What is the Jib Gradle plugin and how does it build a container image differently from a typical Dockerfile-based build?
basics
~10 sJib 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.
What is the Kotlin Multiplatform Gradle plugin, and how do you declare the platforms a module should compile for?
basics
~10 sApply 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.