Configure Gradle for IntelliJ IDEA Project

From Bonus Bits
Jump to: navigation, search

Purpose

This article gives the steps to add the path to a local Gradle install. In this example, Gradle was installed with SDKMan. We do have the option to let IntelliJ handle it and use the Gradle Wrapper, but in the follow I'll be describing using a local installed Gradle.


Prerequisites


Create New Gradle Project

If starting from scratch we can do the following.

  1. Select File | New Project...
  2. Select Gradle
  3. Select Java
  4. Select Next
    Jetbrains intellij idea add gradle to project02
  5. Enter GroupId and ArtifactId
    Jetbrains intellij idea add gradle to project03
  6. Select Next
  7. Enter path to gradle.
    1. Current Example (Recommended) We can switch versions with SDKman and file level configs
      /Users/username/.sdkman/candidates/gradle/current
    2. Specific Example (To hard code to a specific version in IntelliJ)
      /Users/username/.sdkman/candidates/gradle/3.3
    Jetbrains intellij idea add gradle to project04
  8. Select Next
  9. Enter Project name and Project Location
  10. Select Finish


Add Local Gradle Path to Existing Project

  1. Select IntelliJ IDEA | Preferences | Build, Execution, Deployment | Gradle
  2. Select Use Local Gradle Distribution
  3. Enter path to gradle.
    1. Current Example (Recommended) We can switch versions with SDKman and file level configs
      /Users/username/.sdkman/candidates/gradle/current
    2. Specific Example (To hard code to a specific version in IntelliJ)
      /Users/username/.sdkman/candidates/gradle/3.3
    Jetbrains intellij idea add gradle to project01


Icon-Tip-Square-Green.png use which command to find path
which gradle

Default Build Config

When creating a new project IntelliJ should generate the build.gradle and settings.gradle file automatically. If you added Gradle to an existing project it may not make the file. Here's some default examples.

build.gradle

group 'com.bonusbits.jenkins.plugin.active-directory.init'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.5

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}


settings.gradle

rootProject.name = 'com.bonusbits.jenkins.plugin.active-directory.init'


Related Articles