# Get started with Gradle and Kotlin/JVM This tutorial demonstrates how to use IntelliJ IDEA and Gradle to create a JVM console application. To get started, first download and install the latest version of [IntelliJ IDEA](https://www.jetbrains.com/idea/download/). ## Create a project 1. In IntelliJ IDEA, select File | New | Project. 2. In the panel on the left, select Kotlin. 3. Name the new project and change its location, if necessary. Tip: Select the Create Git repository checkbox to place the new project under version control. You will be able to do it later at any time. ![Create a console application](images/jvm-new-gradle-project.png) 4. Select the Gradle build system. 5. From the JDK list, select the [JDK](https://www.oracle.com/java/technologies/downloads/) that you want to use in your project. * 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 don't have the necessary JDK on your computer, select Download JDK. 6. Select Kotlin for the Gradle DSL. 7. Select the Add sample code checkbox to create a file with a sample `"Hello World!"` application. 8. Click Create. You have successfully created a project with Gradle! ### Specify a Gradle version for your project You can explicitly specify a Gradle version for your project under the Advanced Settings section, either by using the Gradle Wrapper or a local installation of Gradle: * Gradle Wrapper: 1. From the Gradle distribution list, select Wrapper. 2. Disable the Auto-select checkbox. 3. From the Gradle version list, select your Gradle version. * Local installation: 1. From the Gradle distribution list, select Local installation. 2. For Gradle location, specify the path of your local Gradle version. ![Advanced settings](images/jvm-new-gradle-project-advanced.png) ## Explore the build script Open the `build.gradle.kts` file. This is the Gradle Kotlin build script, which contains Kotlin-related artifacts and other parts required for the application: ```KOTLIN plugins { kotlin("jvm") version "2.4.21" // Kotlin version to use } group = "org.example" // A company name, for example, `org.jetbrains.kotlin` version = "1.0-SNAPSHOT" // Version to assign to the build artifact repositories { // Sources of dependencies. See 1️⃣ mavenCentral() // Maven Central Repository. See 2️⃣ } dependencies { // All the libraries you want to use. See 3️⃣ // Copy dependencies' names after you find them in a repository testImplementation(kotlin("test")) // The Kotlin test library } kotlin { // Generated JVM toolchain configuration. See 4️⃣ jvmToolchain(25) // The JDK for compiling the project. } tasks.test { // Test task configuration. See 5️⃣ useJUnitPlatform() // JUnitPlatform for tests. See 6️⃣ } ``` * 1️⃣ Lean more about [sources of dependencies](https://docs.gradle.org/current/userguide/declaring_repositories.html). * 2️⃣ The [Maven Central Repository](https://central.sonatype.com/). It can also be [Google's Maven repository](https://maven.google.com/) or your company's private repository. * 3️⃣ Learn more about [declaring dependencies](https://docs.gradle.org/current/userguide/declaring_dependencies.html). * 4️⃣ Learn more about [Java toolchain support](gradle-configure-project.html#gradle-java-toolchains-support). * 5️⃣ Learn more about [tasks](https://docs.gradle.org/current/dsl/org.gradle.api.Task.html). * 6️⃣ [JUnitPlatform for tests](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html#useJUnitPlatform). There are a few Kotlin-specific artifacts in the Gradle build file: 1. In the `plugins {}` block, there is the `kotlin("jvm")` artifact. This plugin defines the version of Kotlin to be used in the project. 2. In the `dependencies {}` block, there is `testImplementation(kotlin("test"))`. Learn more about [setting dependencies on test libraries](gradle-configure-project.html#set-dependencies-on-test-libraries). ## Run the application 1. Open the Gradle window by selecting View | Tool Windows | Gradle: ![Main.kt with main fun](images/jvm-gradle-view-build.png) 2. Execute the build Gradle task in `Tasks/build`. In the Build window, `BUILD SUCCESSFUL` appears. It means that Gradle built the application successfully. 3. In `src/main/kotlin`, open the `Main.kt` file: * `src` directory contains Kotlin source files and resources. * `Main.kt` file contains sample code that will print `Hello World!`. 4. Run the application by clicking the green Run icon in the gutter and select Run 'MainKt'. ![Running a console app](images/jvm-run-app-gradle.png) You can see the result in the Run tool window: ![Kotlin run output](images/jvm-output-gradle.png) Congratulations! You have just run your first Kotlin application. ## What's next? Learn more about: * [Gradle build file properties](https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#N14E9A). * [Targeting different platforms and setting library dependencies](gradle-configure-project.html). * [Compiler options and how to pass them](gradle-compiler-options.html). * [Incremental compilation, caches support, build reports, and the Kotlin daemon](gradle-compilation-and-caches.html).