Gradle init Command
Gradle init Command
Gradle is a powerful build automation tool used primarily for Java projects, but it also supports other languages like Groovy, Kotlin, Scala, etc. It helps automate tasks such as compiling code, running tests, packaging applications, and deploying software. Gradle uses a flexible Groovy or Kotlin DSL (Domain Specific Language) to define the build process.
- Gradle is an open-source build tool based on concepts from Apache Ant and Maven.
- It uses a Directed Acyclic Graph (DAG) to determine the order of tasks execution.
- Supports both declarative and imperative programming models using Groovy or Kotlin.
- Highly customizable and extensible for complex project builds.
Command Syntax
The gradle init
command is used to generate a new Gradle project from scratch. This command helps set up the basic structure of a project, including directories, build scripts, and configuration files. It is especially useful for beginners who want to start quickly without manually creating all the necessary files.
When you run gradle init
, it prompts you to select the type of project (e.g., basic, application, library) and the language you want to use. Gradle then creates a ready-to-use project with sample code and build configurations.
/> gradle init
Example Run
> gradle init Select type of build to generate: 1: Application 2: Library 3: Gradle plugin 4: Basic (build structure only) Enter selection (default: Application) [1..4] 1Select implementation language: 1: Java 2: Kotlin 3: Groovy 4: Scala 5: C++ 6: Swift Enter selection (default: Java) [1..6] 1
Enter target Java version (min: 7, default: 21): 21 Project name (default: project): myproject Select application structure: 1: Single application project 2: Application and library project Enter selection (default: Single application project) [1..2] 1
Select build script DSL: 1: Kotlin 2: Groovy Enter selection (default: Kotlin) [1..2]
Select test framework: 1: JUnit 4 2: TestNG 3: Spock 4: JUnit Jupiter Enter selection (default: JUnit Jupiter) [1..4] 4 Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] no
> Task :init Learn more about Gradle by exploring our Samples at https://docs.gradle.org/8.14/samples/sample_building_java_applications.html BUILD SUCCESSFUL in 1m 30s 1 actionable task: 1 executed C:\Users\testingdocs\project>
This will generate a directory structure with source code files, test directories, and a build.gradle
file to help you get started quickly with Gradle.