Skip to content

Setting up

Ali edited this page Nov 21, 2023 · 2 revisions

Project structure

We will use the following:

  • Gradle (Groovy) v8.2
  • Java 17
  • Spigot 1.17
  • IntelliJ IDEA

Setting up

First, we will create a new project in IntelliJ IDEA.

Project creation dialog

  1. Pick a name. We will go with sun-bans for this project (Sun because Lamp!)
    • Make sure you choose "Java", "Gradle", "JDK 17" and "Groovy".
    • You can optionally choose to create a Git repository
    • We do not want sample code.
  2. Press Create to create a new project.

Setting up Gradle

  1. Head straight to build.gradle

Project structure

  1. We want to add the JitPack repository, as well as Spigot repositories. Add the following to your build.gradle:
repositories {
    mavenCentral()
    
    // The JitPack repository, where Lamp is hosted
    maven { url = "https://jitpack.io/" }

    // Repositories required for Spigot
    maven { url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
    maven { url = "https://oss.sonatype.org/content/groups/public/" }
}
  1. We also want to add our dependencies. Add the following to your build.gradle:
dependencies {
    // The lamp version. This will allow us to easily
    // update it in the future.
    def lamp_version = "3.1.8"

    // Required for all platforms
    implementation("com.github.Revxrsal.Lamp:common:${lamp_version}")

    // The Bukkit API for Lamp
    implementation("com.github.Revxrsal.Lamp:bukkit:${lamp_version}")

    // The Spigot API.
    compileOnly("org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT")

    // The adventure API. It may be required at compile-time
    compileOnly("net.kyori:adventure-platform-bukkit:4.1.2")
}
  1. Because we need Lamp to be present when the plugin is running, we have to bundle it in our plugin. For this, we will use the ShadowJar plugin.
plugins {
    id "com.github.johnrengelman.shadow" version "7.1.2"
    // ^^ add this to your plugins {} block
    id "java"
}
  1. We also want to add parameter naming. This will preserve our parameter names when the plugin runs, allowing Lamp to automatically generate usages and parameter names.

To do this, add the following:

compileJava {
    options.compilerArgs += ["-parameters"]
}

We're done with our build.gradle! Your file should look like this:

plugins {
    id "com.github.johnrengelman.shadow" version "7.1.2"
    id "java"
}

group = "org.example"
version = "1.0"

sourceCompatibility = 17
targetCompatibility = 17

repositories {
    mavenCentral()
    // The JitPack repository, where Lamp is hosted
    maven { url = "https://jitpack.io/" }

    // Repositories required for Spigot
    maven { url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" }
    maven { url = "https://oss.sonatype.org/content/groups/public/" }
}

dependencies {
    // The lamp version. This will allow us to easily
    // update it in the future.
    def lamp_version = "3.1.8"

    // Required for all platforms
    implementation("com.github.Revxrsal.Lamp:common:${lamp_version}")

    // The Bukkit API for Lamp
    implementation("com.github.Revxrsal.Lamp:bukkit:${lamp_version}")

    // The Spigot API
    compileOnly("org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT")

    // The adventure API. It may be required at compile-time
    compileOnly("net.kyori:adventure-platform-bukkit:4.1.2")
}

// Preserve parameter names in command usage
compileJava {
    options.compilerArgs += ["-parameters"]
}
Clone this wiki locally