A first project from gradle init

Gradle writes a project for you. The init task of the build-init plugin asks a few questions and writes the settings file, the build script, the wrapper and the ignore file. This lesson runs it with every question answered on the command line, then reads what came out.

The command

Four flags make the run non-interactive: --type basic writes a build with no plugin at all, --dsl groovy picks build.gradle over build.gradle.kts, --project-name names the project instead of taking the folder name, and --use-defaults accepts every remaining default.

gradle init --type basic --dsl groovy --project-name hello --use-defaults --console=plain --offline --no-daemon


> Task :init
Learn more about Gradle by exploring our Samples at https://docs.gradle.org/9.9.2/samples

BUILD SUCCESSFUL in 12s
1 actionable task: 1 executed

One task, :init, and a link to the samples of the same version. Without --use-defaults the same task would ask for the type, the language of the build scripts and the test framework on the terminal.

What it wrote

ls -A1

.gitattributes
.gitignore
build.gradle
gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

Seven files and a folder. The three that matter first are below; the wrapper (gradlew, gradlew.bat, gradle/wrapper/) has its own lesson.

settings.gradle

/* * This file was generated by the Gradle 'init' task. * * The settings file is used to specify which projects to include in your build. * For more detailed information on multi-project builds, please refer to https://docs.gradle.org/9.9.2/userguide/multi_project_builds.html in the Gradle documentation. */ rootProject.name = 'hello'

One statement and a comment that says where to read more. The settings file is read before the build script and names the project; a build with several projects lists them here.

build.gradle

/* * This file was generated by the Gradle 'init' task. * * This is a general purpose Gradle build. * Learn more about Gradle by exploring our Samples at https://docs.gradle.org/9.9.2/samples */

Nothing but a comment: the basic type applies no plugin, so the build has the built-in tasks only and no compile task. The java type of the same task would write a source tree and apply the Java plugin instead.

gradle.properties

# This file was generated by the Gradle 'init' task. # https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties org.gradle.configuration-cache=true

A properties file with one line, and that line is the default of Gradle 9: the configuration cache is on for a project written by init. It is also the reason the log of the next build says Configuration cache entry stored; the caching lesson takes it apart.

Ask Gradle what it can do

gradle help --console=plain --offline --no-daemon

Calculating task graph as no cached configuration is available for tasks: help

> Task :help

Welcome to Gradle 9.9.2.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see more detail about a task, run gradle help --task <task>

To see a list of command-line options, run gradle --help

For more detail on using Gradle, see https://docs.gradle.org/9.9.2/userguide/command_line_interface.html

For troubleshooting, visit https://help.gradle.org

BUILD SUCCESSFUL in 21s
1 actionable task: 1 executed
Configuration cache entry stored.

The help task prints the three commands a beginner needs: one to run a build, one to list the tasks, one to read a single task. All three have their own lesson in the Tasks chapter.

Where to go next

The files of a Gradle project takes the same folder apart file by file: what belongs in the settings file, in the build script and in gradle.properties, and which folders a build creates on its own.

Related

Автор статьи: Arthur Isaev

Изображение баннера