Gradle plugin

Getting started

Three files turn a multi-module plugin project into a build the plugin configures.

1. Apply the plugin

Add the plugin to the root build.gradle. It resolves from the Gradle Plugin Portal, which every build searches by default:

build.gradle
plugins {
    id 'io.github.mcengine.build-logic' version '0.2.0'
}

Releases are also published to https://maven.pkg.github.com/MCEngine/gradle-plugin. To resolve from there instead, add that repository with GITHUB_ACTOR and a GITHUB_TOKEN that can read packages to pluginManagement { repositories { } } in settings.gradle, beside gradlePluginPortal().

2. Name the project in gradle.properties

The plugin reads four properties:

PropertyUsed for
project-groupThe group of every project
project-versionThe version of every project
git-org-nameThe GitHub owner the published modules go to
git-repositoryThe GitHub repository the published modules go to
gradle.properties
project-group=io.github.example
project-version=1.0.0
git-org-name=Example
git-repository=example-plugin

The last two are needed only when a module is published.

3. Lay out the modules

A typical settings.gradle. Folders without a build file, such as platforms, are left alone:

settings.gradle
plugins {
    id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0'
}

rootProject.name = 'example-plugin'

include 'api'
include 'common'
include 'bukkit'
include 'platforms:spigotmc'
include 'platforms:papermc'
include 'platforms:foliamc'
include 'platforms:engine'

Module builds keep only what is theirs: dependencies, resources and, in the engine, the Shadow configuration. The engine applies Shadow without a version, because the plugin already put it on the classpath:

platforms/engine/build.gradle
plugins {
    id 'com.gradleup.shadow'
}

dependencies {
    implementation project(':bukkit')
    implementation project(':platforms:spigotmc')
    implementation project(':platforms:papermc')
    implementation project(':platforms:foliamc')
}

4. Build

Terminal
./gradlew build                  # compile and test every module
./gradlew :platforms:engine:shadowJar  # the server jar
./gradlew publish                # the published modules, with GITHUB_ACTOR and GITHUB_TOKEN set

Anything that differs from the defaults goes in mcengineBuild { }.

What it configures →