IntelliJ IDEA 2026.1 Help

Getting Started with Gradle

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. The tutorial uses Java 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.

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

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:

    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).

    Gradle project view
  • The dedicated Gradle tool window (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
  • The Gradle settings 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 Build Tool Settings on the toolbar.

    the Gradle settings

    The build and test actions are delegated to Gradle. Also, the Gradle Wrapper ensures the project uses a specific Gradle version.

  • The project structure (Ctrl+Alt+Shift+S) contains information about the project's SDK and a language level used in the project.

    Project Structure

Step 2. Add Java code

Now let's create a Java application that outputs the first 100 FizzBuzz numbers.

Add a Java class to the Gradle project

  1. In the Project tool window (Alt+1), select the src/main/java directory.

  2. Click New File or Directory on the tool window toolbar (or press Alt+Insert) and select Package.

  3. In the New Package dialog, name the package org.gradle.tutorial and press Enter.

  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.

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

    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.

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). 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
  3. Open the created test class in the editor and add the following code:

    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.

Run main class from the editor

  1. Open the FizzBuzzProcessor.java class in the editor. Click the gutter icon and select Run 'FizzBuzzProcessor.main()' to run the application.

    Run application in Gradle
  2. Check the result in the Run tool window.

    Run tool window

Step 4. Run tests

Now, let's run the created test.

Run tests in a Gradle project

  • Open the FizzBuzzTest.java test class in the editor. Click the Run Test gutter icon next to class definition and select Run 'FizzBuzzTest'.

    Gradle Run test from the gutter

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

Run tool window /test passed

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

Run tool window / test failed

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.

  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:

    tasks.jar { manifest { attributes["Main-Class"] = "org.gradle.tutorial.FizzBuzzProcessor" } from({ configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) } }) }
  3. Click 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

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

    Project tool window: build directory
  5. Check the Run tool window for the results.

    Run tool window: build task

    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

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 popup.

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:

    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.

  3. Click 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
  5. In the Gradle tool window, click Run anything 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
  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

Summary

In this tutorial, you have learned how to:

Next steps

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

For a full list of available tutorials, refer to IntelliJ IDEA tutorials.

31 March 2026