Gradle の設定

SpongeGradle の使用

Using SpongeGradle is very simple and allows you to minimize the necessary Gradle configuration for setting up a Sponge plugin on Gradle. Additionally, it provides integration for プラグインのメタデータ, such as automatically contributing the group, project name, version and description defined in your build script to the built plugin, so you only need to update your plugin version in one file.

ちなみに

Most problems are caused by attempting to use an outdated Gradle version. We recommend using the latest Gradle version together with SpongeGradle. The Gradle section of the build systems page explains how to setup Gradle on your computer.

Below is a simple template that should be usable for most plugins. Make sure to replace the group with the group ID you have chosen before.

plugins {
    id 'org.spongepowered.plugin' version '0.8.1'
}

group = 'com.example' // TODO
version = '1.0-SNAPSHOT'
description = 'An example plugin'

dependencies {
    compile 'org.spongepowered:spongeapi:6.0.0'
}

この数行で、通常手動で行う設定のほとんどを処理します:

  • 基本の Gradle Java セットアップ

  • Java 8 でコンパイルするようにプロジェクトを設定する

  • Add Sponge’s Maven repository (and Maven Central)

  • Set up a plugin with the project name in lower case as plugin ID

  • Automatically includes the project name, description and version in プラグインのメタデータ.

プラグイン ID の手動設定

By default, the Gradle plugin will configure your plugin ID with project name (in lowercase) you have configured. If you want to use a custom plugin ID and still use the プラグインのメタデータ integration you can change it manually:

sponge {
    plugin {
        id = 'mypluginid'
    }
}

デフォルトの書き換え

By default the Gradle plugin will contribute the plugin name, plugin version and description automatically to プラグインのメタデータ with defaults defined in the project properties. It is also possible to override these if you want to specify them manually:

sponge {
    plugin {
        meta {
            name = 'My Plugin'
            version = '1.0.0'
            description = 'This is a plugin'
        }
    }
}

You can also remove a default value entirely:

sponge {
    plugin {
        meta {
            description = null
        }
    }
}

Without SpongeGradle

警告

We recommend using SpongeGradle for Gradle plugins since it will provide additional Gradle integration for Sponge plugins.

Generally, everything necessary to compile a Sponge plugin using Gradle can be done by simply adding the SpongeAPI dependency to your project:

repositories {
    mavenCentral()
    maven {
        name = 'sponge'
        url = 'https://repo.spongepowered.org/maven'
    }
}

dependencies {
    compile 'org.spongepowered:spongeapi:6.0.0'
}