# Getting Started with Gradle

> **TL;DR**
> Required plugins: Gradle and Gradle for Java ([installed and enabled](managing-plugins.html#open-plugin-settings) by default)
>
>
>
> Tutorial Gradle version: 9.3.0
>
>
>
> Tutorial JDK version: 25
>
>
>
> Tutorial JUnit version: 6

This tutorial will teach you how to create and manage Gradle-based projects in IntelliJ IDEA. You will learn how to create, run and test a Gradle application, and create and run an executable JAR file using Gradle.

You can find the project used in this tutorial on [GitHub](https://github.com/JetBrains/ij_tutorial_gradle). The tutorial uses [Java 25](https://openjdk.org/projects/jdk/25/) syntax.

## Step 1. Create a project

Let’s create a new Java project with the Gradle build system that will become the basis of our application.

Procedure: Create a new Gradle Project

1. Launch IntelliJ IDEA.

If the Welcome screen opens, click New Project.

Otherwise, go to `File | New Project` in the main menu.

2. In the New Project wizard, select Java from the New Project list.

3. Name the project (for example, `FizzBuzz`) and change the default location if necessary.

4. Select Gradle as the Build system.

5. From the JDK list, select the latest available Oracle OpenJDK version.

If the JDK is installed on your computer but not defined in the IDE, select Add JDK and specify the path to the JDK home directory.

If you do not have the necessary JDK on your computer, select Download JDK.

6. Select Kotlin as the Gradle DSL and leave the Add sample code option disabled.

7. Open the Advanced Settings node. Select the Auto-select option for the Gradle version.

8. Leave default values in the ArtifactId and GroupId fields. Click Create.

![New Gradle project](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle_project_wizard_start.png)

After that, IntelliJ IDEA will create and load the new Gradle-based project. Let’s examine its components in more detail:

* IntelliJ IDEA creates a `build.gradle.kts` file with the following code: ```KOTLIN plugins { id("java") } group = "org.example" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { testImplementation(platform("org.junit:junit-bom:6.0.0")) testImplementation("org.junit.jupiter:junit-jupiter") testRuntimeOnly("org.junit.platform:junit-platform-launcher") } tasks.test { useJUnitPlatform() } ``` IntelliJ IDEA automatically adds a test dependency when creating a project.

* IntelliJ IDEA also creates the `src` directory with `main` and `test` subdirectories. You can find them in the Project tool window (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS)) ). ![Gradle project view](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle_project_view.png)

* The dedicated [Gradle tool window](jetgradle-tool-window.html) (`View | Tool Windows | Gradle`) with a linked project and its default tasks becomes available. We will use this tool window to run tutorial tasks. ![Gradle tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle_tool_window.png)

* The [Gradle settings](gradle-settings.html) in your project are used to store the information about the linked projects, Gradle JVM, and build actions. You can quickly access them from the Gradle tool window by clicking ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.settings.svg) Build Tool Settings on the toolbar. ![the Gradle settings](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle_settings_FizzBuzz.png) The build and test actions are delegated to Gradle. Also, the Gradle Wrapper ensures the project uses a specific Gradle version.

* The [project structure](project-settings-and-structure.html) (`Ctrl+Alt+Shift+S` (Windows), `⌘ ;` (macOS), `⌘ ;` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ Comma` (macOS System Shortcuts), `Ctrl+Alt+Shift+S` (XWin), `Ctrl+Alt+Shift+S` (GNOME), `Ctrl+Alt+Shift+S` (KDE), `Ctrl+Alt+Shift+S` (Emacs), `Ctrl+Alt+Shift+S` (Sublime Text), `⌘ ;` (Sublime Text (macOS)), `Ctrl+Alt+Shift+S` (NetBeans), `Ctrl+Alt+Shift+S` (Visual Studio), `⌘ ;` (Visual Studio (macOS)), `Ctrl+Alt+Shift+S` (Eclipse), `⌘ ;` (Eclipse (macOS))) contains information about the project's SDK and a language level used in the project. ![Project Structure](https://resources.jetbrains.com.cn/help/img/idea/2026.2/project_structure_FizzBuzz.png)

## Step 2. Add Java code

Now let's create a Java application that outputs the first 100 [FizzBuzz](https://en.wikipedia.org/wiki/Fizz_buzz) numbers.

Procedure: Add a Java class to the Gradle project

1. In the Project tool window (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))), select the `src/main/java` directory.

2. Click ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.add.svg) New File or Directory on the tool window toolbar (or press `Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Ctrl+N` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `Alt+Insert` (NetBeans), `Ctrl+N` (Visual Studio), `⌘ N` (Visual Studio (macOS)), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS))) and select Package.

3. In the New Package dialog, name the package `org.gradle.tutorial` and press `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (NetBeans), `Enter` (Visual Studio), `⏎` (Visual Studio (macOS)), `Enter` (Eclipse), `⏎` (Eclipse (macOS)).

4. In the Project tool window, right-click the created package and select `New | Java Class`.

5. Specify a name for your Java class (for example, `FizzBuzzProcessor`) and press `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (NetBeans), `Enter` (Visual Studio), `⏎` (Visual Studio (macOS)), `Enter` (Eclipse), `⏎` (Eclipse (macOS)).

6. Add the following code to the main `FizzBuzzProcessor.java` class:

```JAVA
package org.gradle.tutorial;

public class FizzBuzzProcessor {
    private FizzBuzzProcessor() {
    }

    static void main(String[] args) {
        for (int i = 1; i <= 100; i++) {
            System.out.println(convert(i));
        }
    }

    public static String convert(int fizzBuzz) {
        if (fizzBuzz % 15 == 0) {
            return "FizzBuzz";
        }
        if (fizzBuzz % 3 == 0) {
            return "Fizz";
        }
        if (fizzBuzz % 5 == 0) {
            return "Buzz";
        }
        return String.valueOf(fizzBuzz);
    }
}
```

Our application is ready. Let's create the necessary tests for it.

Procedure: Create a test class

1. Open the `FizzBuzzProcessor.java` class in the editor, place the caret at the class name, and go to `Navigate | Test` (`Ctrl+Shift+T` (Windows), `⌘ ⇧ T` (macOS), `⌘ ⇧ T` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ T` (macOS System Shortcuts), `Ctrl+Shift+T` (XWin), `Ctrl+Shift+T` (GNOME), `Ctrl+Shift+T` (KDE), `Ctrl+Shift+T` (Emacs), `Ctrl+Shift+T` (Sublime Text), `Ctrl+Shift+T` (Sublime Text (macOS)), `Ctrl+Shift+T` (NetBeans), `Ctrl+Shift+T` (Visual Studio), `Ctrl+Shift+T` (Visual Studio (macOS)), `Ctrl+Shift+T` (Eclipse), `Ctrl+Shift+T` (Eclipse (macOS))). Click Create New Test.

2. In the Create Test dialog, select `JUnit6` as the Testing library and make sure that `org.gradle.tutorial` as the Destination package is selected.

In the Class name field, specify a name for the test class (for example, `FizzBuzzTest`) and leave the rest of the default options as is. Click OK.

![The Create Test dialog](https://resources.jetbrains.com.cn/help/img/idea/2026.2/create_test_FizzBuzz.png)

3. Open the created test class in the editor and add the following code:

```JAVA
package org.gradle.tutorial;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class FizzBuzzTest {
    @Test
    public void FizzBuzzNormalNumbers() {
        Assertions.assertEquals
                ("1", FizzBuzzProcessor.convert(1));
        Assertions.assertEquals
                ("2", FizzBuzzProcessor.convert(2));
    }

    @Test
    public void FizzBuzzThreeNumbers() {
        Assertions.assertEquals
                ("Fizz", FizzBuzzProcessor.convert(3));
    }

    @Test
    public void FizzBuzzFiveNumbers() {
        Assertions.assertEquals
                ("Buzz", FizzBuzzProcessor.convert(5));
    }

    @Test
    public void FizzBuzzThreeAndFiveNumbers() {
        Assertions.assertEquals
                ("FizzBuzz", FizzBuzzProcessor.convert(15));
    }
}
```

## Step 3. Run the application with Gradle

Let's run the application to see if it works.

Procedure: Run main class from the editor

1. Open the `FizzBuzzProcessor.java` class in the editor. Click the ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.gutter.run.svg) gutter icon and select Run 'FizzBuzzProcessor.main()' to run the application.

![Run application in Gradle](https://resources.jetbrains.com.cn/help/img/idea/2026.2/run_java_app_in_gradle_project.png)

2. Check the result in the [Run tool window](run-tool-window.html).

![Run tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/run_java_app_with_gradle_result.png)

## Step 4. Run tests

Now, let's run the created test.

Procedure: Run tests in a Gradle project

* Open the `FizzBuzzTest.java` test class in the editor. Click the ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.actions.runAll.svg) Run Test gutter icon next to class definition and select Run 'FizzBuzzTest'.

![Gradle Run test from the gutter](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle_run_test_editor.png)

The result of the test will be displayed in the Run tool window.

![Run tool window /test passed](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle_test_result_passed.png)

If you change the default number in one of the tests, it will fail.

![Run tool window / test failed](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle_test_failed.png)

The Run tool window displays information about the failed test including the specific line of the code where the error occurred.

## Step 5. Create an executable JAR file

Let's build our application to create an executable JAR file.

Procedure:

1. In the Project tool window, find the `build.gradle.kts` file and open it in the editor.

2. Add the following code as a separate element at the end of the file:

```KOTLIN
tasks.jar {
    manifest {
        attributes["Main-Class"] = "org.gradle.tutorial.FizzBuzzProcessor"
    }

    from({
        configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }
    })
}
```

3. Click ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle.icons.gradleLoadChanges.svg) Sync Gradle Changes in the editor to synchronize the changes to your project.

4. In the Gradle tool window, open the project's node, then go to the `Tasks | build` node, and double-click the `build` task to run it.

![Gradle tool window: build task](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle_tool_window_build.png)

IntelliJ IDEA creates the `build` directory that contains your JAR file.

![Project tool window: build directory](https://resources.jetbrains.com.cn/help/img/idea/2026.2/project_tool_window_build.png)

5. Check the Run tool window for the results.

![Run tool window: build task](https://resources.jetbrains.com.cn/help/img/idea/2026.2/run_tool_window_build_task.png)

Note that the build task includes the test task that Gradle executes. So, if you make a mistake in one of the tests, the test task will fail and the build task will fail as well.

![Run tool window: build with failed test](https://resources.jetbrains.com.cn/help/img/idea/2026.2/run_tool_window_test_fail.png)

## Step 6. Run the JAR file with Gradle

Let's make a few adjustments to the `build.gradle.kts` file so that you can execute your JAR file in the [Run anything](running-anything.html) popup.

Procedure: Run the JAR file

1. In the Project tool window, find the `build.gradle.kts` file and open it in the editor.

2. Change the code at the top of the file as follows:

```KOTLIN
plugins {
    id ("java")
    id ("application")
}

application {
    mainClass.set("org.gradle.tutorial.FizzBuzzProcessor")
}
```

The final version of the `build.gradle.kts` file, including all changes, is available on [GitHub](https://github.com/JetBrains/ij_tutorial_gradle/blob/master/build.gradle.kts).

3. Click ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle.icons.gradleLoadChanges.svg) Sync Gradle Changes in the editor to synchronize the changes to your project.

4. In the Gradle tool window, open the project's Tasks node. Gradle added the new distribution node here. Open this node and double-click the `assembleDist` task to run it.

IntelliJ IDEA creates additional subdirectories in the `build` directory.

![Project tool window: build directory](https://resources.jetbrains.com.cn/help/img/idea/2026.2/project_view_build_app.png)

5. In the Gradle tool window, click ![Run anything](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.runAnything.svg) Execute Gradle Task on the toolbar.

6. In the Run Anything popup that opens, find the `gradlew :run` command and double-click it.

![Run anything: gradlew run](https://resources.jetbrains.com.cn/help/img/idea/2026.2/run_anything_gradle_run.png)

7. Check the result in the Run tool window. It should be the same as when you ran the application from the IntelliJ IDEA editor.

![Run tool window: run task output](https://resources.jetbrains.com.cn/help/img/idea/2026.2/gradle_run_app_task_output.png)

## Summary

In this tutorial, you have learned how to:

* [Create and manage Gradle-based projects](#create_project) in IntelliJ IDEA

* [Create](#create_test) and [run tests](#run_test_gradle) using Gradle

* [Create](#deploy_gradle) and [run an executable JAR file](#run_terminal) using Gradle

## Next steps

Learn how to complete other tasks using Gradle in IntelliJ IDEA from these tutorials:

* [Publish a Java library to a Maven repository](add-a-gradle-library-to-the-maven-repository.html)

* [Set up JNI development in Gradle project](setting-up-jni-development-in-gradle-project.html)

For a full list of available tutorials, refer to [IntelliJ IDEA tutorials](instance-tutorials.html).

## See also

### Procedures

[Gradle](gradle.html)

### Reference

[Settings](settings-preferences-dialog.html) [Gradle settings](gradle-settings.html)

