skip to content

Command-Line Invocation

Driving Gradle from the shell: selecting and excluding tasks, passing properties, controlling execution, and turning up diagnostics. Interviewers ask because CLI fluency is the quickest signal of hands-on experience.

on this pageshow

explore

questions

page 1 of 2

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

level: juniorimportance: must knowfreq 55%

answer

  1. -t / --continuous
  2. Waiting for changes to input files
  3. watches declared task INPUTS only
  4. Ctrl-D to exit
  5. re-runs same task graph

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.

solid answer

~40 s

Continuous build is enabled with `-t` or `--continuous`. Instead of executing the requested tasks once and exiting, Gradle keeps running, monitors the files declared as **inputs** of the executed task graph, and re-triggers the same build whenever one of those inputs changes. It is ideal for tight feedback loops — e.g. `gradle -t test` re-runs tests on every source edit. Only changes to files that are actual declared task inputs cause a rebuild; unrelated files are ignored. Between runs Gradle prints "Waiting for changes to input files..." and you exit with Ctrl-D (or Ctrl-C). It relies on file-system watching to detect changes efficiently, and pairs naturally with incremental tasks and the build cache so each re-run does minimal work.

code

bash · 5 lines
bash
# Re-run tests automatically on every source change
gradle -t test

# Equivalent long form
gradle --continuous test

go deeper

for a junior

Know the flag (-t/--continuous), that Gradle stays alive and re-runs on input changes, and how to exit.

for a middle

Explain that only declared task inputs trigger a rebuild and tie that to correct @Input.../inputs declarations.

for a senior

Discuss pairing with incremental tasks, the daemon, and the build cache for fast iteration, and continuous build's limits with long-running tasks.

for a principal

Frame it within team feedback-loop strategy vs. external watchers/CI, and the implications of input-correctness on whether continuous mode is trustworthy.

## What continuous build is Normally `gradle build` executes the requested task graph **once** and the JVM process exits. **Continuous build** — `gradle -t <tasks>` or the long form `gradle --continuous <tasks>` — changes that: after the first execution Gradle does **not** exit. It prints `Waiting for changes to input files...` and parks, watching the files that fed the build. When a watched file changes, Gradle re-executes the **same** task graph automatically. You stop it with Ctrl-D (graceful) or Ctrl-C. ## Why only *inputs* trigger a rebuild Every task declares its inputs via `@InputFile`, `@InputFiles`, `@InputDirectory`, `@Classpath`, etc. (or the runtime `inputs.file(...)` API). Continuous build computes the **union of all declared inputs** of the tasks that actually executed, and watches exactly those paths. A change to a file that is *not* a declared input of any executed task is ignored — this is why correct input declarations matter: an under-declared task will silently fail to rebuild when its real input changes. ## Typical uses ```bash gradle -t test # re-run tests on every source/test edit gradle -t :app:run # (with appropriate setup) restart on change gradle --continuous build # full build loop ``` ## Relationship to incrementality Continuous build does **not** make a single task faster — each re-run is a normal build. Its speed comes from pairing with **incremental tasks**, **up-to-date checking**, and the **build cache**: most tasks will be `UP-TO-DATE` or `FROM-CACHE`, so only the genuinely affected work re-runs. Combined with the always-on **Gradle daemon**, configuration and JVM warm-up are reused across iterations. ## Limits - It re-runs the build; it does **not** hot-reload a running application by itself. - Tasks that themselves block forever (a long-running server) hold the loop until they finish, so continuous build is most natural for finite tasks like `compileJava`, `test`, codegen. - Build-logic / `build.gradle(.kts)` changes are not reliably picked up the same way source changes are — you generally restart for build-script edits.

  • If you edit a file and the continuous build does NOT re-run, what is the most likely cause?
    That file is not a declared input of any task that executed, so Gradle is not watching it — usually an under-declared task input. Add the proper @Input.../inputs.file(...) declaration.
  • How do you exit a continuous build cleanly?
    Press Ctrl-D for a graceful shutdown (or Ctrl-C to interrupt).

saying these in an interview costs you the question

  • Saying continuous build watches the whole project tree — it watches only declared task inputs.
  • Claiming it hot-reloads a running app automatically; it re-runs the build, not the live process.

context

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

A build script reads project.property("flavor") but users often run without -Pflavor. How do you read it safely with a default?

level: juniorimportance: must knowfreq 60%

basics

~10 s

project.property throws if the property is missing. Use findProperty("flavor") (returns null) with an Elvis default, or providers.gradleProperty("flavor").getOrElse("default").

open as a page

When you run `./gradlew test` in a multi-project build, how is that different from running `./gradlew :app:test`? Explain unqualified task names versus fully qualified task paths.

level: juniorimportance: must knowfreq 70%

basics

~10 s

An unqualified name like test runs the task in every project that has it (within the current project and its subprojects). A qualified path like :app:test targets exactly one project's task.

open as a page

When and how do you use `dependencyInsight`, and how does it differ from `dependencies`?

level: middleimportance: must knowfreq 68%

basics

~20 s

dependencyInsight traces why one specific module is on the classpath and which version won. You run gradle dependencyInsight --dependency <name> --configuration <name>. dependencies shows the whole tree; dependencyInsight is a focused, reverse view of one dependency.

open as a page

What does `--rerun-tasks` do, and how does it differ from `clean build`?

level: middleimportance: must knowfreq 60%

basics

~10 s

--rerun-tasks forces every selected task to execute, ignoring up-to-date checks and the build cache, without deleting outputs. clean build instead deletes the build/ directory first, then runs.

open as a page

Which built-in report tasks help you understand a project from the command line, and what does each tell you?

level: middleimportance: must knowfreq 65%

basics

~10 s

Run tasks to list available tasks, dependencies to print the dependency tree, properties to dump project properties, and help for general help or help --task <name> for details on a specific task.

open as a page

A Gradle build fails with a one-line error and no cause. Which flags do you add to get a full stack trace, and what's the difference between them?

level: middleimportance: must knowfreq 60%

basics

~10 s

Re-run with --stacktrace (-s) to print the exception's stack trace, or --full-stacktrace (-S) for the complete trace including Gradle's internal frames. By default Gradle truncates the trace.

open as a page

You pass -Ddb.url=... on the command line but your test fails to read it. Why, and how do you make it visible to the tests?

level: middleimportance: must knowfreq 55%

basics

~10 s

Tests run in a forked JVM, so the daemon's -D system property isn't inherited. Propagate it explicitly: tasks.test { systemProperty("db.url", providers.systemProperty("db.url").get()) }.

open as a page

What does the `-x` / `--exclude-task` flag do, and how does excluding a task interact with the task dependency graph?

level: middleimportance: must knowfreq 55%

basics

~10 s

-x <task> (or --exclude-task) removes a task from the execution graph for this run. The excluded task and any task that would run only as its dependency are skipped, while requested tasks still run.

open as a page

In a continuous build, a teammate edits a config file consumed by a custom task but the build does not re-run. Diagnose the cause and explain how task input declarations govern continuous build triggering.

level: seniorimportance: must knowfreq 30%

basics

~20 s

Continuous build only watches files declared as task inputs. If the custom task reads the config file without declaring it via @InputFile/inputs.file(...), Gradle doesn't watch it, so editing it triggers nothing. Add the input declaration to fix it.

open as a page

What do the built-in `properties` and `projects` tasks report, and how do they help inspect the build model from the CLI?

level: juniorimportance: should knowfreq 40%

basics

~20 s

gradle properties prints the project's properties (name, group, version, plus extra/ext and many built-ins). gradle projects prints the project hierarchy of a multi-project build as a tree with each subproject's path. Both are read-only model inspectors.

open as a page

What does the `--dry-run` flag do in Gradle, and when is it useful?

level: juniorimportance: should knowfreq 55%

basics

~10 s

--dry-run (-m) makes Gradle compute and print the ordered list of tasks it would run, each marked SKIPPED, without actually executing any of them. It's a safe preview of the execution graph.

open as a page

How do you discover the exact name and command-line options of a task you want to run, without leaving the terminal?

level: juniorimportance: should knowfreq 40%

basics

~10 s

Run gradle tasks to list available tasks, then gradle help --task <name> to see that task's full path, type, description, and any CLI options.

open as a page

What are the practical limitations of continuous build, and which kinds of tasks is it well- or poorly-suited for?

level: middleimportance: should knowfreq 26%

basics

~20 s

Continuous build re-runs the build, it does not hot-reload a running app. It suits finite tasks (compile, test, codegen) for fast feedback. It is poor for tasks that block forever (servers) and does not reliably react to build-script edits.

open as a page

How does Gradle's file-system watching (org.gradle.vfs.watch) work, and what role does it play in continuous build and normal incremental builds?

level: middleimportance: should knowfreq 38%

basics

~20 s

Gradle keeps an in-memory virtual file system (VFS) of file hashes/metadata. With org.gradle.vfs.watch=true (default), the OS notifies the daemon of changes between builds so Gradle reuses the VFS instead of re-hashing everything. Continuous build uses these notifications to detect input changes.

open as a page

What does the `buildEnvironment` task report, and why is it distinct from `dependencies`?

level: middleimportance: should knowfreq 45%

basics

~20 s

buildEnvironment prints the dependency tree of the buildscript classpath — the plugins and libraries used to configure the build itself, from buildscript { dependencies { classpath … } }. dependencies covers your application's configurations instead.

open as a page

What does the `--continue` flag change about how Gradle handles task failures, and what are the trade-offs?

level: middleimportance: should knowfreq 58%

basics

~10 s

By default Gradle stops at the first task failure. --continue makes it keep executing every task that doesn't depend on a failed one, then report all failures at the end and exit non-zero.

open as a page

What does the `--offline` flag do, and how does it interact with Gradle's dependency cache?

level: middleimportance: should knowfreq 50%

basics

~10 s

--offline tells Gradle never to access the network during the build. It resolves dependencies purely from the local dependency cache and fails if a required artifact or metadata isn't already cached.

open as a page

If a project property is set both in gradle.properties and via -P on the command line, which one wins, and how do you reason about it?

level: middleimportance: should knowfreq 45%

basics

~10 s

The command-line -P value wins. CLI flags override gradle.properties for the same property name. The same holds for -D versus systemProp. entries.

open as a page

A developer runs `./gradlew tst` and gets an error; another runs `./gradlew comp` and gets a different error. How does Gradle resolve a task selector, and what are the failure modes for an unmatched or ambiguous name?

level: middleimportance: should knowfreq 35%

basics

~20 s

Gradle tries to match the selector as an exact name, then as a camelCase abbreviation. If nothing matches you get a 'task not found' error (often with did-you-mean suggestions); if the abbreviation matches several tasks you get an 'ambiguous abbreviation' error listing candidates.

open as a page

Explain Gradle's camelCase task-name abbreviation. Why does `./gradlew cT` often resolve to `compileTestJava`, and when does abbreviation fail?

level: middleimportance: should knowfreq 45%

basics

~20 s

Gradle lets you abbreviate a task name by typing the leading letters of each camelCase word. cT expands to a task whose words start c…T…, like compileTest. It fails if the abbreviation matches zero or more than one task.

open as a page

What do `outgoingVariants` and `resolvableConfigurations` report, and when would you use each?

level: seniorimportance: should knowfreq 38%

basics

~20 s

outgoingVariants lists what your project publishes/exposes to consumers — the consumable configurations, their attributes, and artifacts. resolvableConfigurations lists what your project consumes — the resolvable configurations and the attributes they request. Together they explain variant-aware resolution.

open as a page

How would you combine Gradle execution-control flags to reproduce a flaky CI failure locally, and how do they interact?

level: seniorimportance: should knowfreq 40%

basics

~10 s

Combine them by intent: --rerun-tasks forces fresh execution, --continue surfaces all failures, --offline removes network variance, and -x drops unrelated slow tasks — e.g. gradle check --rerun-tasks --continue --offline -x lint.

open as a page

When triaging a CI build failure you can't reproduce locally, would you reach for --info/--debug or a build scan, and why?

level: seniorimportance: should knowfreq 45%

basics

~10 s

Prefer a build scan (--scan): it captures a complete, shareable web report of the failure. Use --info for quick local context and --debug only as a noisy last resort.

open as a page

What subtle pitfalls arise with -Pflag and -PenableX=true when treating project properties as booleans?

level: seniorimportance: should knowfreq 35%

basics

~10 s

Project properties are strings. -Pflag with no value sets it to an empty string (still present, so hasProperty is true). -Pflag=false is the string "false", which is truthy unless you call toBoolean().

open as a page

When you run `./gradlew clean build` versus `./gradlew build clean`, does the order of the task arguments matter? Explain how Gradle orders multiple requested tasks.

level: seniorimportance: should knowfreq 40%

basics

~20 s

Listing multiple tasks requests them all in one run. Command-line order is honored only as a tie-break; real ordering comes from task dependencies and mustRunAfter/shouldRunAfter. clean build and build clean can both work because clean and build have no hard dependency between them, but the requested order biases scheduling.

open as a page

showing 1–30 of 31