LoginSignup
11
7

More than 5 years have passed since last update.

KotlinでSpigotプラグインを作るためのbuild.gradle

Last updated at Posted at 2016-12-28

筆者環境

OS IDE
macOS Sierra 10.12.2 IntelliJ IDEA CE

build.gradle

build.gradle
group 'com.MasahiroSaito.Spigot'
version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.0.5'

    repositories {
        mavenCentral()
        maven {
            name = "spigot-api"
            url "https://hub.spigotmc.org/nexus/content/groups/public"
        }
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath "net.md-5:bungeecord-chat:1.10-SNAPSHOT"
        classpath group: 'org.spigotmc', name: 'spigot-api', version: '1.11-R0.1-SNAPSHOT'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'java'
apply plugin: 'kotlin'

sourceCompatibility = 1.8

configurations {
    embed
    compile.extendsFrom(embed)
}

repositories {
    mavenCentral()
    maven {
        name = "spigot-api"
        url "https://hub.spigotmc.org/nexus/content/groups/public"
    }
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots/"
    }
}

dependencies {
    compile "net.md-5:bungeecord-chat:1.10-SNAPSHOT"
    compile group: 'org.spigotmc', name: 'spigot-api', version: '1.11-R0.1-SNAPSHOT'
    embed "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

jar {
    from configurations.embed.collect { it.isDirectory() ? it : zipTree(it) }
}

解説

  • spigot-api のバージョンは作成するプラグインのバージョンによって変更する
  • プラグインの情報を適宜変更する

プラグインの group と version 設定

group 'com.MasahiroSaito.Spigot'
version '1.0-SNAPSHOT'

IDEA でプロジェクトを作成した時に入力したものが、そのまま記述されている。
プラグインのバージョンを変更する際は、version の中身を書き換える。

version はビルド後のファイル名に影響してくるため、前のバージョンを上書きしたくない場合は、ビルド前に記述を変えると良い。

ビルド後の jar に Kotlin ライブラリも同梱

configurations {
    embed
    compile.extendsFrom(embed)
}

dependencies {
    compile "net.md-5:bungeecord-chat:1.10-SNAPSHOT"
    compile group: 'org.spigotmc', name: 'spigot-api', version: '1.11-R0.1-SNAPSHOT'
    embed "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

jar {
    from configurations.embed.collect { it.isDirectory() ? it : zipTree(it) }
}

ビルド後の jar に Kotlin ライブラリを同梱することで、Spigot サーバーにプラグインを導入する際に Kotlin ライブラリを導入する必要がなくなる。ただし、ファイルを大きくなるため、たくさんプラグインを作成する際は前提プラグインなどを作成し、そのプラグインにのみ同梱するなどの工夫は必要かもしれない。

ビルド時に必要な情報

buildscript {
    ext.kotlin_version = '1.0.5'

    repositories {
        mavenCentral()
        maven {
            name = "spigot-api"
            url "https://hub.spigotmc.org/nexus/content/groups/public"
        }
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath "net.md-5:bungeecord-chat:1.10-SNAPSHOT"
        classpath group: 'org.spigotmc', name: 'spigot-api', version: '1.11-R0.1-SNAPSHOT'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

依存関係に必要なリポジトリ

repositories {
    mavenCentral()
    maven {
        name = "spigot-api"
        url "https://hub.spigotmc.org/nexus/content/groups/public"
    }
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots/"
    }
}

参考

11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7