Skip to content

2) IntelliJ IDEA Setup

Florian Spieß edited this page Jul 31, 2022 · 37 revisions

This wiki page is migrating to jda.wiki/setup/intellij


IntelliJ IDEA Setup

Download

Older versions of IntelliJ IDEA

This describes the changes for older versions of IntelliJ IDEA

Click to expand
  1. Open the Project view

  2. Create a new Project

    project

  3. Select Gradle > Java

  4. Configure your SDK to use Java 1.8

    gradle

  5. Click Next and fill in your groupId and your artifactId. Example: me.name and bot

    artifact

  6. Check Use auto-import and click Next > Finish

    settings

  7. Continue with step 5 of the tutorial for newer IntelliJ IDEA versions

For newer versions of IntelliJ IDEA

  1. Navigate to "New Project" from any view

  2. Select Gradle -> Java as the type of Project and make sure the correct JDK is selected (Java8 or higher)

    new_project

  3. Provide a title for your project and define your GroupId and optionally the ArtifactId and initial Version in the "Artifact Coordinates" subsection

    artifact_setup

  4. Optionally enable Auto-Importing of the gradle file in the Gradle Settings

    gradle_settings auto_import

Note: this is also the place where you could switch the runner for your project (By default, Gradle is used to run your application and tests)

  1. Let intellij index your project.
  2. Open build.gradle
  3. Populate the build file with the following
    plugins {
        id'application'
        id'com.github.johnrengelman.shadow' version '5.2.0'
    }
    
    mainClassName = 'com.example.jda.Bot'
    
    version '1.0'
    def jdaVersion = 'JDA_VERSION_HERE'
    
    sourceCompatibility = targetCompatibility = 1.8
    
    repositories {
        mavenCentral()
        maven { // on kotlin dsl use `maven("https://m2.dv8tion.net/releases")` instead
            url "https://m2.dv8tion.net/releases"
        }
    }
    
    dependencies {
        implementation("net.dv8tion:JDA:$jdaVersion")
    }
    
    compileJava.options.encoding = 'UTF-8'

Note: Replace the JDA_VERSION_HERE with the one mentioned here (release) or with the latest build here
Replace the mainClassName value with the path to your main class later on!

  1. If IntelliJ IDEA didn't already do so automatically, set up a source folder as src/main/java
  2. Create your group package. Example: me.name.bot
  3. Make your main class. Example: Bot.java. Your directory tree should look like this:
    ProjectName -> src/main/java -> me/name/bot -> Bot.java
                -> gradle/wrapper -> gradle-wrapper.properties
                -> gradle/wrapper -> gradle-wrapper.jar
                -> build.gradle
                -> settings.gradle
    
  4. Configure the mainClassName value in the build.gradle to your class. Example: me.name.bot.Bot
  5. To build your finished project simply use the shadowJar task in your gradle tool window on right hand side of your editor. This will build a jar in build/libs. The one with the -all suffix is the shadow jar.

    You can also run your project with the run gradle task!

  6. Setup Logback
  7. Continue with Getting Started