Complete Kotlin-DSL Gradle scripting for multiple projects.

Added the shadow plugin integration with the entire project. Indvidual
modules each have their designated dependencies and each will assign
various dependencies based on constants now made through buildSrc.

Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com>
This commit is contained in:
Gabriel Harris-Rouquette 2019-02-16 18:39:44 -08:00
parent 196ace4b81
commit 8645ce641d
No known key found for this signature in database
GPG Key ID: F34C08E5B2D67A0A
16 changed files with 431 additions and 68 deletions

View File

@ -1,33 +1,45 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
buildscript {
repositories {
jcenter()
maven("https://files.minecraftforge.net/maven/")
}
dependencies {
classpath("net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT")
}
}
// Extras
var core by extra { project("core") }
// Bukkit/Spigot plugins
// Things used by other projects
Projects.core = project("core")
Projects.bukkit = project("bukkit")
Projects.sponge = project("sponge")
var core: Project by extra { project("core") }
val bukkit by extra { project("bukkit") }
val bukkit_18 by extra { bukkit.project("1_8_8") }
val bukkit_112 by extra { bukkit.project("1_12") }
val bukkit_113 by extra { bukkit.project("1_13") }
// Sponge plugins
val sponge by extra { project("sponge") }
val sponge_7 by extra { sponge.project("api7") }
val configurate by extra { ""}
group = properties["pluginGroup"]!!
version = properties["pluginVersion"]!!
plugins {
`java-library`
java
`maven-publish`
id("com.github.johnrengelman.shadow") version "4.0.4"
}
configurations {
create("childJars")
}
val childJars: Configuration by configurations
// Set up defaults for all projects, maven repositories, java compatibility level and compiling encoding
allprojects {
apply(plugin="java-library")
@ -36,16 +48,17 @@ allprojects {
repositories {
mavenCentral()
// World Edit
maven("https://maven.sk89q.com/repo")
maven(Repos.sk89q)
// bStats
maven("https://repo.codemc.org/repository/maven-public")
maven(Repos.bstats)
// configurate
maven(Repos.sponge)
// spigot
maven(Repos.spigot)
maven(Repos.sonatype)
mavenLocal()
}
dependencies {
compile("org.apache.tomcat", "tomcat-jdbc", "7.0.52") // tomcat JDBC
compile("org.apache.tomcat", "tomcat-juli", "7.0.52") // tomcat juli
testCompile("junit", "junit", "4.12")
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
@ -53,22 +66,42 @@ allprojects {
tasks.getting(JavaCompile::class) {
options.encoding = "UTF-8"
}
val shadowJar by tasks.getting(ShadowJar::class) { // Configure basics of relocation
relocate(Shadow.Origin.juli, Shadow.Target.juli)
relocate(Shadow.Origin.tomcat, Shadow.Target.tomcat)
exclude(Shadow.Exclude.ForgeGradle.dummyThing)
exclude(Shadow.Exclude.ForgeGradle.template)
}
}
val jar by tasks.getting(Jar::class) {
manifest {
attributes(mapOf(
"Implementation-Title" to "mcMMO",
"Implementation-Version" to rootProject.properties["pluginVersion"]!!,
"Main-Class" to "com.gmail.nossr50.mcMMO" // Main plugin class for bukkit
))
// Sub projects don't need to shadow their dependencies. This eliminates common ones
subprojects {
val shadowJar by tasks.getting(ShadowJar::class) {
dependencies {
exclude(dependency("${Deps.Groups.sponge}:${Deps.Modules.configurate_yaml}"))
exclude(dependency(Shadow.Exclude.guava))
exclude(dependency(Shadow.Exclude.snakeyaml))
exclude(dependency(Shadow.Exclude.tomcat))
exclude(dependency(Shadow.Exclude.juli))
}
}
}
val shadowJar by tasks.getting(ShadowJar::class) {
dependencies {
include(project("core"))
include(dependency("org.bstats:bstats-bukkit:1.4"))
}
relocate("org.bstats", "com.gmail.nossr50.metrics.bstat")
dependencies {
compile(bukkit)
compile(sponge)
compile(bukkit_18)
compile(bukkit_112)
compile(bukkit_113)
compile(sponge_7)
}
val shadowJar by tasks.getting(ShadowJar::class) { // Root shadow relocation
relocate(Shadow.Origin.bstatsBukkit, Shadow.Target.bstatsBukkit)
baseName = "mcMMO"
classifier = "bundle"
}
val build by tasks
build.dependsOn(shadowJar)

View File

@ -0,0 +1,3 @@
plugins {
`kotlin-dsl`
}

View File

@ -0,0 +1,188 @@
@file:Suppress("MayBeConstant", "unused")
import org.gradle.api.Project
object Plugins {
const val spongeGradleId = "${Deps.Groups.sponge}.plugin"
object FG2_3 {
const val classpath = "net.minecraftforge.gradle:ForgeGradle:${Versions.fg23}"
const val extensionName = "minecraft"
const val id = "net.minecraftforge.gradle.forge"
}
}
object Repos {
const val sk89q = "https://maven.sk89q.com/repo"
// bStats
const val bstats = "https://repo.codemc.org/repository/maven-public"
// configurate
const val sponge = "https://repo.spongepowered.org/maven/"
const val spigot = "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
const val sonatype = "https://oss.sonatype.org/content/repositories/snapshots"
const val forge = "https://files.minecraftforge.net/maven/"
}
object Config {
object Libs {
const val configurate = "${Deps.Groups.sponge}:${Deps.Modules.configurate_yaml}:${Versions.configurate}"
const val jdbc = "${Deps.Groups.tomcat}:${Deps.Modules.jdbc}:${Versions.jdbc}"
const val juli = "${Deps.Groups.tomcat}:${Deps.Modules.juli}:${Versions.jdbc}"
const val junitDep = "${Deps.Groups.junit}:${Deps.Modules.junit}:${Versions.junit}"
object Bukkit {
object `1_8` {
const val api = "$bukkit:${Versions.bukkit18}"
const val spigotApi = "${Bukkit.spigotApi}:${Versions.bukkit18}"
const val spigot = "$${Bukkit.spigot}:${Versions.bukkit18}"
const val nms = "$craftbukkit:${Versions.bukkit18}"
// only legacy existed at this point, no core.
const val wgLegacy = "${Bukkit.wgLegacy}:${Versions.wg18}"
}
object `1_12` {
const val api = "$bukkit:${Versions.bukkit112}"
const val spigotApi = "${Bukkit.spigotApi}:${Versions.bukkit112}"
const val spigot = "$${Bukkit.spigot}:${Versions.bukkit112}"
const val nms = "$craftbukkit:${Versions.bukkit112}"
// only legacy existed at this point, no core.
const val wgLegacy = "${Bukkit.wgLegacy}:${Versions.wg112}"
}
object `1_13` {
const val api = "$bukkit:${Versions.bukkit113}"
const val spigotApi = "${Bukkit.spigotApi}:${Versions.bukkit113}"
const val spigot = "$${Bukkit.spigot}:${Versions.bukkit113}"
const val nms = "$craftbukkit:${Versions.bukkit113}"
const val wgCore = "${Bukkit.wgCore}:${Versions.wg113}"
const val wgLegacy = "${Bukkit.wgLegacy}:${Versions.wg113}"
}
const val bukkit = "${Deps.Groups.bukkit}:${Deps.Modules.bukkit}"
const val craftbukkit = "${Deps.Groups.bukkit}:${Deps.Modules.craftbukkit}"
const val wgCore = "${Deps.Groups.worldguard}:${Deps.Modules.wgCore}"
const val wgLegacy = "${Deps.Groups.worldguard}:${Deps.Modules.wgLegacy}"
const val spigotApi = "${Deps.Groups.spigot}:${Deps.Modules.spigotApi}"
const val spigot = "${Deps.Groups.spigot}:${Deps.Modules.spigot}"
const val bstats = "${Deps.Groups.bstats}:${Deps.Modules.bstatsBukit}:${Versions.bstats}"
}
object Sponge {
object API7 { // All of these are specific to the API7 module, API8 will change
const val forgeGradleId = "net.minecraftforge.gradle.forge"
const val spongeGradleId = "${Deps.Groups.sponge}.plugin"
const val spongeGradleVersion = "0.9.0"
const val api = "${Sponge.api}:${Versions.sapi7}"
const val common = "${Sponge.common}:${Versions.spongeImpl7}"
const val forge_version = "14.23.5.2768"
const val minecraftVersion = "1.12.2-$forge_version"
const val mappings = "snapshot_20180808"
}
object Exclude {
const val group = Deps.Groups.sponge
const val module = Deps.Modules.spongeAPI
}
const val api = "${Deps.Groups.sponge}:${Deps.Modules.spongeAPI}"
const val common = "${Deps.Groups.sponge}:${Deps.Modules.spongecommon}"
const val bstats = "${Deps.Groups.bstats}:${Deps.Modules.bstatsSponge}:${Versions.bstats}"
}
}
}
object Deps {
object Groups {
const val nossr = "com.gmail.nossr50"
const val google = "com.google"
const val guava = "com.google.guava"
const val gson = "com.google.code.gson"
const val yaml = "org.yaml"
const val sk89q = "com.sk89q"
const val apache = "org.apache"
const val worldguard = "$sk89q.worldguard"
const val worldedit = "$sk89q.worldedit"
const val sponge = "org.spongepowered"
const val spigot = "org.spigotmc"
const val md5 = "net.md_5"
const val bukkit = "org.bukkit"
const val bstats = "org.bstats"
const val tomcat = "org.apache.tomcat"
const val junit = "junit"
const val checker = "org.checkerframework"
}
object Modules {
const val guava = "guava"
const val gson = "gson"
const val snakeyaml = "snakeyaml"
const val wgCore = "worldguard-core"
const val wgLegacy = "worldguard-legacy"
const val bungeecordChat = "bungeecord-chat"
const val spongeAPI = "spongeapi"
const val spongecommon = "spongecommon"
const val spongeforge = "spongeforge"
const val spongevanilla = "spongevanilla"
const val bukkit = "bukkit"
const val craftbukkit = "craftbukkit"
const val bstatsBukit = "bstats-bukkit"
const val bstatsSponge = "bstats-sponge"
const val spigotApi = "spigot-api"
const val spigot = "spigot"
const val configurate = "configurate"
const val configurate_core = "${configurate}-core"
const val configurate_yaml = "${configurate}-yaml"
const val jdbc = "tomcat-jdbc"
const val juli = "tomcat-juli"
const val junit = "junit"
const val checker = "checker-qual"
}
}
object Projects {
var core: Project? = null
var bukkit: Project? = null
var sponge: Project? = null
}
object Shadow {
object Origin {
const val juli = "${Deps.Groups.apache}.juli"
const val tomcat = "${Deps.Groups.apache}.tomcat"
const val apache = "${Deps.Groups.apache}.commons.logging"
const val bstatsBukkit = "${Deps.Groups.bstats}.bukkit"
const val configurate = "ninja.leaping.configurate"
const val checker = "org.checkerframework"
}
object Target {
const val juli = "${Deps.Groups.nossr}.database.tomcat.juli"
const val tomcat = "${Deps.Groups.nossr}.database.tomcat"
const val apache = "${Deps.Groups.nossr}.commons.logging"
const val bstatsBukkit = "${Deps.Groups.nossr}.metrics.bstat"
const val configurate = "${Deps.Groups.nossr}.${Deps.Modules.configurate}"
const val checker = "${Deps.Groups.nossr}.${Deps.Modules.configurate}.checkerframework"
}
object Exclude {
const val tomcat = "${Deps.Groups.tomcat}:${Deps.Modules.jdbc}"
const val juli = "${Deps.Groups.apache}:${Deps.Modules.juli}"
const val guava = "${Deps.Groups.guava}:${Deps.Modules.guava}"
const val snakeyaml = "${Deps.Groups.yaml}:${Deps.Modules.snakeyaml}"
const val bukkit = Deps.Groups.bukkit
const val spigot = Deps.Groups.spigot
const val sk89q = "com.sk89q"
const val wg = "$sk89q.worldguard"
const val intake = "$sk89q.intake"
const val flyway = "com.flywaydb"
const val khelekore = "org.khelekore"
const val findbugs = "com.google.code.findbugs"
const val bstats = "${Deps.Groups.bstats}"
object ForgeGradle {
const val dummyThing = "dummyThing"
const val template = "Version.java.template"
}
}
}

View File

@ -0,0 +1,15 @@
object Versions {
const val configurate = "3.6" // Latest configurate
const val bukkit18 = "1.8.8-R0.1-SNAPSHOT" // Last bukkit 1.8.8
const val bukkit112 = "1.12.2-R0.1-SNAPSHOT" // Last bukkit 1.12.2
const val bukkit113 = "1.13.2-R0.1-SNAPSHOT" // Latest bukkit
const val sapi7 = "7.1.0" // Latest SpongeAPI stable
const val spongeImpl7 = "7.1.5" // Latest SpongeCommon stable
const val jdbc = "7.0.52"
const val junit = "4.12"
const val fg23 = "2.3-SNAPSHOT" // ForgeGradle to support MC 1.12.2
const val wg18 = "6.1.2" // Bukkit/CraftBukkit/Spigot 1.8.8 supported build, works on newer, but last one to support 1.8.8
const val wg112 = "6.2" // Last WorldGuard to support 1.12
const val wg113 = "7.0.0-SNAPSHOT" // Latest WorldGuard to support 1.13.2
const val bstats = "1.4" // Supports all backwards compatible. Always relocated
}

View File

@ -1,10 +1,12 @@
import Config.Libs.Bukkit.`1_12` as Bukkit
plugins {
java
}
dependencies {
implementation("org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT") // Spigot API
implementation("com.sk89q.worldguard", "worldguard-legacy", "6.2") // WorldGuard
compileOnly(Bukkit.api) // Spigot API
compileOnly(Bukkit.nms)
compileOnly(Bukkit.wgLegacy) // WorldGuard
}

View File

@ -1,10 +1,12 @@
import Config.Libs.Bukkit.`1_13` as Bukkit
plugins {
`java-library`
}
dependencies {
implementation("org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT") // Spigot API
implementation("com.sk89q.worldguard", "worldguard-core", "7.0.0-SNAPSHOT") // WorldGuard
implementation("com.sk89q.worldguard", "worldguard-legacy", "7.0.0-SNAPSHOT") // NEEDED
compileOnly(Bukkit.api) // Bukkit API
compileOnly(Bukkit.nms)
compileOnly(Bukkit.wgCore) // WorldGuard
compileOnly(Bukkit.wgLegacy) // WG for Bukkit
}

View File

@ -1,10 +1,12 @@
import Config.Libs.Bukkit.`1_8` as Bukkit
plugins {
java
}
dependencies {
implementation("org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT") // Spigot API
implementation("com.sk89q.worldguard:worldguard-legacy:6.1.2") // Old worldguard
compileOnly(Bukkit.api) // Spigot API
compileOnly(Bukkit.wgLegacy) // Old worldguard
compileOnly(Bukkit.nms)
}

View File

@ -0,0 +1,12 @@
package com.gmail.nossr50.platform.bukkit;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.block.CraftBlock;
public class Testing18 {
Material material;
CraftBlock block;
}

View File

@ -1,21 +1,18 @@
buildscript {
repositories { jcenter() }
dependencies { classpath("com.github.jengelman.gradle.plugins:shadow:4.0.4") }
}
val bukkit: Project by rootProject.extra
val core: Project by rootProject.extra
// This configures the bukkit/spigot ecosystem repositories, so they all share the same repos
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import Config.Libs.Bukkit as Bukkit
val bukkit: Project = Projects.bukkit!!
val core: Project = Projects.core!!
allprojects {
repositories {
// Spigot & Bukkit
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/repositories/snapshots")
mavenLocal() // For nms variants
}
dependencies {
compile(core) // includes junit for tests
compile("org.bstats", "bstats-bukkit", "1.4") // Bukkit bstats
implementation(Bukkit.bstats) // Bukkit bstats
}
val shadowJar by tasks.getting(ShadowJar::class) {
relocate(Shadow.Origin.bstatsBukkit, Shadow.Target.bstatsBukkit)
}
}
@ -23,12 +20,35 @@ subprojects {
dependencies {
// Provide the base bukkit plugin dependency for plugin classloading.
// All "versioned" implementations will be properly classloaded by the bukkit parent
(compile(bukkit) as ModuleDependency).apply { exclude("org.spigotmc") }
compileOnly(bukkit)
}
}
plugins {
java
}
dependencies {
implementation("org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT") // Spigot API
// Temporary dependencies while things are being moved.
compileOnly(Bukkit.`1_13`.spigotApi) { // Spigot API
isTransitive = true
}
compileOnly(Bukkit.`1_13`.api) { // Spigot API
isTransitive = true
}
compileOnly(Bukkit.`1_13`.wgCore) {
isTransitive = true
exclude(group = Shadow.Exclude.sk89q)
exclude(group = Shadow.Exclude.intake, module = "intake")
exclude(group = Shadow.Exclude.sk89q, module = "squirrelid")
exclude(group = Shadow.Exclude.flyway)
exclude(group = Shadow.Exclude.khelekore)
exclude(group = Shadow.Exclude.findbugs)
}
compileOnly(Bukkit.`1_13`.wgLegacy) {
isTransitive = true
exclude(group = Shadow.Exclude.bukkit)
exclude(group = Shadow.Exclude.sk89q, module = "commandbook")
exclude(group = Shadow.Exclude.bstats)
}
}

View File

@ -0,0 +1,12 @@
package com.gmail.nossr50;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
public class BukkitBlockType {
private Material material;
private BlockData blockData;
}

View File

@ -1,4 +1,22 @@
import Config.Libs as Libs
plugins {
java
`java-library`
id("com.github.johnrengelman.shadow")
}
dependencies {
compile(Libs.configurate) {
exclude(Deps.Groups.guava, Deps.Modules.guava)
exclude(Deps.Groups.checker, Deps.Modules.checker)
}
compile(Libs.jdbc)
compile(Libs.juli)
testCompile(Libs.junitDep)
// Spigot for in-dev dependency
compileOnly(Libs.Bukkit.`1_13`.spigotApi) {
isTransitive = false
}
}

View File

@ -26,6 +26,7 @@ pluginManagement {
repositories {
jcenter()
maven("https://repo.spongepowered.org/maven/")
maven("https://files.minecraftforge.net/maven/")
gradlePluginPortal()
}
}

View File

@ -1,12 +1,47 @@
plugins {
java
// Apply the spongegradle plugin to generate the metadata file
id("org.spongepowered.plugin") version "0.9.0" // supplies sponge repo and plugin metadata creation tasks
import net.minecraftforge.gradle.user.UserBaseExtension
import Config.Libs.Sponge.API7 as API7
buildscript {
repositories {
jcenter()
maven(Repos.forge)
}
dependencies {
classpath(Plugins.FG2_3.classpath)
}
}
// Extension created to set up the minecraft block for ForgeGradle. This should change in FG3.
val Project.minecraft: UserBaseExtension
get() = extensions.getByName<UserBaseExtension>(Plugins.FG2_3.extensionName)
plugins {
`java-library`
// Apply the spongegradle plugin to generate the metadata file
id(Config.Libs.Sponge.API7.spongeGradleId) version Config.Libs.Sponge.API7.spongeGradleVersion // supplies sponge repo and plugin metadata creation tasks
}
apply(plugin = API7.forgeGradleId)
dependencies {
compile("org.spongepowered", "spongeapi", "7.1.0") // SpongeAPI
compile("org.bstats", "bstats-sponge", "1.4") // Sponge bstats
compileOnly(API7.api) // SpongeAPI
}
configure<UserBaseExtension> {
version = API7.minecraftVersion
runDir = "run"
mappings = API7.mappings
}
tasks.withType<Jar> {
inputs.properties += "version" to project.version
inputs.properties += "mcversion" to project.minecraft.version
baseName = "mcmmo"
filesMatching("/mcmod.info") {
expand(mapOf(
"version" to project.version,
"mcversion" to project.minecraft.version
))
}
}
description = "mcMMO for Sponge"

View File

@ -0,0 +1,3 @@
mod_name = "mcmmo"
mod_version = "2.2-SNAPSHOT"
mc_version = "1.12.2"

View File

@ -0,0 +1,19 @@
package com.gmail.nossr50.sponge.api7;
import net.minecraft.item.Item;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.GameRegistryEvent;
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.plugin.Plugin;
@Plugin(id = "mcmmo", name = "mcMMO", description = "mcMMO for Sponge")
public class API7Plugin {
@SuppressWarnings("ConstantConditions")
@Listener
public void onRegister(GameRegistryEvent.Register<ItemType> event) {
Item derp = new Item(); // NMS!!!
event.register((ItemType) derp); // Since sponge mixes into Item, we can cast.
}
}

View File

@ -1,31 +1,29 @@
import Config.Libs.Sponge as Sponge
plugins {
java
}
val core: Project by rootProject.extra
val sponge: Project by rootProject.extra
val core = Projects.core!! // because it's a var and potentially null by declaration
val sponge = Projects.sponge!! // because it's a var and potentially null by declaration
description = "mcMMO for Sponge"
repositories {
// sponge
maven("https://repo.spongepowered.org/maven")
}
dependencies {
implementation(group="org.spongepowered", name="spongeapi", version="7.1.0") // Base version
compile(Sponge.bstats) // Bstats is used for all sponge versions
compileOnly(Sponge.API7.api) // Base version
}
allprojects {
dependencies {
compile(core)
compile(Projects.core!!)
}
}
subprojects {
dependencies {
(compile(sponge) as ModuleDependency).apply {
exclude("org.spongepowered")
(compileOnly(sponge) as ModuleDependency).apply {
exclude(Sponge.Exclude.group, Sponge.Exclude.module)
}
}
}