Step 1: Set Up Gradle Project with Groovy DSL

1. Create and Initialize the Project

cd ~
mkdir HelloGradleGroovy
cd HelloGradleGroovy
gradle init --type java-application --dsl groovy --overwrite

Choose defaults by pressing Enter for each prompt.

Screenshot_20250515_164549.png

2. Verify Project Structure

The gradle init command creates a standard project layout. To view this structure in your terminal, you can use the tree command.

Run the following command in your project's root directory (HelloGradleGroovy):

tree

Screenshot_20250515_164932.png

3. Update app/build.gradle

Open the file:

gedit app/build.gradle

Replace its contents with:

plugins {
    // Apply the Java plugin for compiling Java code
    id 'java'
    // Apply the application plugin to add support for building an application
    id 'application'
}

group = 'org.example'
version = '1.0'

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
}

dependencies {
    // Define your dependencies. Use JUnit Jupiter (JUnit 5) for testing.
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
    // If using parameterized tests
    testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0'
}

application {
    // Define the main class for the application.
    mainClass = 'org.example.App'
}

// A custom task example: printing a greeting
task hello {
    doLast {
        println 'Hello, Gradle!'
    }
}

4. Dependency Management (For Information Only – Can Be Skipped)

Dependencies are declared in the dependencies block. Gradle resolves them from the repositories configured above, like Maven Central.

Example:

dependencies{
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0' 
    // Example: Adding a test dependency
}

Gradle will download these automatically during the build process.