skip to content

Build Init

The gradle init task for scaffolding a project: type, DSL choice, test framework, and the wrapper it generates alongside the scripts. Asked as the fastest way to see an idiomatic build layout for an unfamiliar project type.

on this pageshow

questions

6

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

level: juniorimportance: must knowfreq 55%

answer

  1. build-init plugin task
  2. generates settings + build scripts
  3. creates the Gradle wrapper
  4. interactive prompts or flags
  5. run with system gradle once

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.

solid answer

~40 s

`gradle init` is the entry-point task of the bundled `build-init` plugin. Run from an empty (or existing) directory, it bootstraps a new build: it writes `settings.gradle(.kts)`, one or more `build.gradle(.kts)` scripts, a skeleton `src/main` + `src/test` layout, a `.gitignore`, and—critically—the **Gradle wrapper** (`gradlew`, `gradlew.bat`, `gradle/wrapper/*`) so collaborators don't need Gradle pre-installed. Interactively it asks for the project type (e.g. `java-application`, `kotlin-library`), the build DSL (Kotlin or Groovy), the test framework, and a project name. All of those can be supplied non-interactively as flags (`--type`, `--dsl`, `--test-framework`) for CI or scripting. Because you usually run it before Gradle is installed locally, you invoke the system `gradle` once, then switch to `./gradlew` thereafter.

code

bash · 12 lines
bash
# Interactive scaffold
gradle init

# Fully non-interactive (CI-friendly)
gradle init \
  --type java-application \
  --dsl kotlin \
  --test-framework junit-jupiter \
  --project-name myapp

# After init, always use the wrapper
./gradlew build

go deeper

for a junior

Know that gradle init scaffolds a new project and creates the wrapper; be able to run it interactively.

for a middle

Explain the flags (--type, --dsl, --test-framework) and the full set of generated artifacts including settings, build scripts, and version catalog.

for a senior

Discuss running it non-interactively in tooling, migrating from Maven, and why the wrapper guarantees reproducible builds.

for a principal

Frame init as a standardization lever—seeding org-wide conventions (DSL choice, version catalogs, test framework) consistently across new repos.

## What `init` is `init` is a task contributed by the **`build-init` plugin**, one of the plugins Gradle bundles into its distribution. You don't apply it in a build script—it's available from a system `gradle` install (or even an empty directory) so it can create a build *from scratch*. ## What it generates For a typical application type, `gradle init` produces: - `settings.gradle.kts` (or `.groovy`) declaring `rootProject.name` and included subprojects. - `build.gradle.kts` for each generated project/subproject with plugins, dependencies, and a configured test framework. - A source skeleton: `app/src/main/...` and `app/src/test/...` with a sample class and test. - The **Gradle wrapper**: `gradlew`, `gradlew.bat`, `gradle/wrapper/gradle-wrapper.jar`, and `gradle/wrapper/gradle-wrapper.properties`. This pins the Gradle version so everyone builds reproducibly. - A `.gitignore` and (for newer types) a `gradle/libs.versions.toml` version catalog. ## Interactive vs non-interactive Run with no arguments, `init` *interactively prompts* for: type, implementation language, build DSL, test framework, project name, and source package. Each prompt can be pre-answered with a flag so the task is fully scriptable: ```bash gradle init --type java-application --dsl kotlin --test-framework junit-jupiter --project-name myapp ``` ## Why the wrapper matters Because `init` is often the *first* Gradle command in a project's life, generating the wrapper means the next person who clones the repo runs `./gradlew build` with the exact pinned Gradle version—no manual install, no version drift. After `init`, you stop using the system `gradle` and use `./gradlew`. ## Detecting existing projects If you run `init` in a directory that already contains a Maven `pom.xml`, the plugin can migrate it (`--type pom`). In an empty directory with no flags it asks what to build.

  • Why does `init` generate the Gradle wrapper?
    So the project pins its Gradle version and teammates/CI can build with `./gradlew` without any local Gradle install, guaranteeing a reproducible version.
  • Do you apply the build-init plugin in your build script?
    No. It's bundled into the Gradle distribution and exposed automatically by a system `gradle` install (or from an empty directory), so its `init` task is always available.

saying these in an interview costs you the question

  • Claiming you must add `build-init` to the plugins block—it's bundled, not applied.
  • Saying `init` only writes a build script and forgetting it also generates the wrapper and source skeleton.

context

open as a page

What does the `--type` flag control in `gradle init`, and what happens if you omit it?

level: middleimportance: must knowfreq 45%

basics

~10 s

--type selects the project template to scaffold—e.g. java-application, kotlin-library, java-library, basic. It determines the plugins, source layout, and sample code generated. Omitting it makes init prompt interactively (or infer from an existing pom.xml).

open as a page

Why does `gradle init` also generate the Gradle wrapper, and what files make it up?

level: middleimportance: must knowfreq 42%

basics

~10 s

init generates the wrapper so the new project pins a specific Gradle version everyone uses via ./gradlew, without installing Gradle manually. The wrapper is four files: gradlew, gradlew.bat, gradle/wrapper/gradle-wrapper.jar, and gradle/wrapper/gradle-wrapper.properties.

open as a page

What does `--dsl` control in `gradle init`, and how would you decide between `kotlin` and `groovy`?

level: middleimportance: should knowfreq 40%

basics

~10 s

--dsl selects the build-script language for the generated scripts: kotlin produces *.gradle.kts files, groovy produces *.gradle files. Kotlin DSL gives type-safe, IDE-friendly scripts and is now the recommended default.

open as a page

How does `--test-framework` work in `gradle init`, and which frameworks are available?

level: middleimportance: should knowfreq 35%

basics

~10 s

--test-framework picks the testing library wired into the generated build and sample test—e.g. junit (JUnit 4), junit-jupiter (JUnit 5), testng, spock (Groovy), or kotlintest. It adds the right dependencies and configures tasks.test (e.g. useJUnitPlatform()).

open as a page

What does the `--incubating` flag do in `gradle init`, and when would you use it?

level: seniorimportance: nice to knowfreq 20%

basics

~20 s

--incubating makes gradle init opt into the latest, possibly-unstable APIs and conventions for the generated build—e.g. newer test-suite or version-catalog defaults—and unlocks incubating project types. It signals you accept that those features may still change.

open as a page