Resource Spigradle - Intelligent gradle plugin for developing Spigot Plugin

Discussion in 'Spigot Plugin Development' started by EntryPointKR, Mar 12, 2020.

  1. Introduction
    If you have experience of developing Spigot plugin, then you maybe created a plugin.yml at least one time.
    How is it? if you create plugins many times, it will be annoying thing. Because in plugin.yml: main, name, version; already we provided at project creating time, and a main class is detectable at compile time.

    and we must write long informations like dependencies, repositories in build.gradle.
    How can we make better to do this?

    Overview
    Spigradle is a gradle plugin aims to smartly generate a plugin.yml and allows you using shortcuts for dependencies and repositories related with bukkit.

    In plugin.yml properties, spigradle will set:
    • main: Spigradle will find a main class that extends JavaPlugin (or presented by @kr.entree.spigradle.Plugin annotation) in your project.
    • name: project.name in build.gradle.
    • version: project.version in build.gradle.
    So if you create a simple plugin that just uses main, name, version in plugin.yml, then just apply the Spigradle without configuring and you're all set.

    • First, it requires 'version', even if you using Gradle; The 'version' already provided in build.gradle.
    • Second, annotation does not suitable for providing many information; we sometimes use commands and permissions.
    • Third, we can use it dynamically with Gradle.
    Also, we can use shortcuts for dependencies and repositories!

    Apply plugin
    Code (Text):
    plugins {
        id 'kr.entree.spigradle' version '1.2.4'
    }
    Code (Text):
    plugins {
       id("kr.entree.spigradle") version "1.2.4"
    }

    Full Example
    Code (Text):
    plugins {
       id 'java'
       id 'kr.entree.spigradle' version '1.2.4'
    }

    group 'org.example'
    version '1.0-SNAPSHOT'

    sourceCompatibility = 1.8

    repositories {
       mavenCentral()
       protocolLib()
       jitpack() // For vault
    }

    dependencies {
       compileOnly paper('1.15.2') // Or spigot()
       compileOnly protocolLib()
       compileOnly vault()
       testImplementation 'junit:junit:4.12'
    }

    spigot {
       authors = ['Me']
       depends = ['ProtocolLib']
       apiVersion = '1.15'
       load = STARTUP
       commands {
           give {
               aliases = ['i']
               description = 'Give command.'
               permission = 'test.foo'
               permissionMessage = 'You do not have permission!'
               usage = '/<command> [test|stop]'
           }
       }
       permissions {
           'test.foo' {
               description = 'Allows foo command'
               defaults = 'true'
           }
           'test.*' {
               description = 'Wildcard permission'
               defaults = 'op'
               children = ['test.foo': true]
           }
       }
    }
    Code (Text):
    import kr.entree.spigradle.attribute.*
    import kr.entree.spigradle.kotlin.*

    plugins {
       kotlin("jvm") version "1.3.70"
       id("kr.entree.spigradle") version "1.2.4"
    }

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

    repositories {
       mavenCentral()
       protocolLib()
       jitpack() // For vault
    }

    dependencies {
       compileOnly(paper("1.15.1")) // Or spigot()
       compileOnly(protocolLib())
       compileOnly(vault())
       testImplementation("junit:junit:4.12")
    }

    spigot {
       authors = listOf("Me")
       depends = listOf("ProtocolLib")
       apiVersion = "1.15"
       load = Load.STARTUP
       commands {
           create("give") {
               aliases = listOf("i")
               description = "Give command."
               permission = "test.foo"
               permissionMessage = "You do not have permission!"
               usage = "/<command> [test|stop]"
           }
       }
       permissions {
           create("test.foo") {
               description = "Allows foo command"
               defaults = "true"
           }
           create("test.*") {
               description = "Wildcard permission"
               defaults = "op"
               children = mapOf("test.foo" to true)
           }
       }
    }


    I hope it's helpful for you.
    If it is, please star the project on GitHub. Thanks!
     
    #1 EntryPointKR, Mar 12, 2020
    Last edited: May 1, 2020
    • Winner Winner x 5
    • Useful Useful x 1
  2. Thank you, this is really great. Would recommend bumping the default version on everything up to 1.15.2 however
     
  3. Good idea. but I'm afraid it brings code changes to users when update spigradle. But I will consider it :)
     
  4. Simply don't provide a default value then, it's not really needed anyway. If you continue providing one, call it "latest" instead of "default", so the user expects it to change.
     
  5. Nice feedback. I'll update it with dependency shortcut for bungeecord-api. Thanks!
    // EDIT: Okay, I bumped up default version to 1.15.2 and added bungeecord() dependency on 1.2.1 just now.
     
    #5 EntryPointKR, Mar 12, 2020
    Last edited: Mar 13, 2020
  6. I just switched from Maven to Gradle and this is perfect! Thank you very much for this plugin.
     
    • Like Like x 1