Clean up gradle build scripts

Adds run-paper plugin support as well as moves majority of logic to kotlin build scrips

Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
This commit is contained in:
Jason 2021-06-07 05:17:39 -07:00 committed by GitHub
parent ff9f93fba4
commit 19b4da07b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 385 additions and 236 deletions

5
.gitignore vendored
View File

@ -18,8 +18,11 @@
# Build files # Build files
.gradle/ .gradle/
jars/ /jars/
out/ out/
build/ build/
target/ target/
*.class *.class
# Run directory
/run/

View File

@ -1,3 +1,7 @@
plugins {
id("essentials.shadow-module")
}
dependencies { dependencies {
compileOnly('com.github.milkbowl:VaultAPI:1.7') { compileOnly('com.github.milkbowl:VaultAPI:1.7') {
exclude group: "org.bukkit", module: "bukkit" exclude group: "org.bukkit", module: "bukkit"

View File

@ -1,3 +1,7 @@
plugins {
id("essentials.module-conventions")
}
dependencies { dependencies {
compileOnly project(':EssentialsX') compileOnly project(':EssentialsX')
} }

View File

@ -1,3 +1,7 @@
plugins {
id("essentials.module-conventions")
}
dependencies { dependencies {
compileOnly project(':EssentialsX') compileOnly project(':EssentialsX')
} }

View File

@ -1,3 +1,7 @@
plugins {
id("essentials.shadow-module")
}
dependencies { dependencies {
compileOnly project(':EssentialsX') compileOnly project(':EssentialsX')
implementation 'com.maxmind.geoip2:geoip2:2.12.0' implementation 'com.maxmind.geoip2:geoip2:2.12.0'

View File

@ -1,3 +1,7 @@
plugins {
id("essentials.module-conventions")
}
dependencies { dependencies {
compileOnly project(':EssentialsX') compileOnly project(':EssentialsX')
} }

View File

@ -1,3 +1,7 @@
plugins {
id("essentials.module-conventions")
}
dependencies { dependencies {
compileOnly project(':EssentialsX') compileOnly project(':EssentialsX')
} }

View File

@ -1,3 +1,7 @@
plugins {
id("essentials.shadow-module")
}
dependencies { dependencies {
compileOnly project(':EssentialsX') compileOnly project(':EssentialsX')
implementation 'org.igniterealtime.smack:smack:3.2.1' implementation 'org.igniterealtime.smack:smack:3.2.1'

View File

@ -0,0 +1,14 @@
plugins {
`kotlin-dsl`
`groovy-gradle-plugin`
}
repositories {
gradlePluginPortal()
}
dependencies {
implementation("net.kyori", "indra-common", "2.0.5")
implementation("gradle.plugin.com.github.jengelman.gradle.plugins", "shadow", "7.0.0")
implementation("xyz.jpenilla", "run-paper", "1.0.2")
}

View File

@ -0,0 +1,51 @@
import net.kyori.indra.git.IndraGitExtension
import org.eclipse.jgit.lib.Ref
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.revwalk.RevWalk
import org.gradle.api.Project
final class GitUtil {
private GitUtil() {
}
static int commitsSinceLastTag(Project project) {
def indraGit = project.extensions.findByType(IndraGitExtension.class)
if (indraGit == null || !indraGit.isPresent() || indraGit.tags().isEmpty()) {
return -1
}
def tags = indraGit.tags()
def depth = 0
def walk = new RevWalk(indraGit.git().getRepository())
def commit = walk.parseCommit(indraGit.commit())
while (true) {
for (tag in tags) {
if (walk.parseCommit(tag.getLeaf().getObjectId()) == commit) {
walk.dispose()
return depth
}
}
depth++
commit = walk.parseCommit(commit.getParents()[0])
}
}
static String headBranchName(Project project) {
if (System.getenv("GITHUB_HEAD_REF") != null && !System.getenv("GITHUB_HEAD_REF").isEmpty()) {
return System.getenv("GITHUB_HEAD_REF")
} else if (System.getenv("GITHUB_REF") != null && !System.getenv("GITHUB_REF").isEmpty()) {
return System.getenv("GITHUB_REF").replaceFirst("refs/heads/", "")
}
def indraGit = project.extensions.findByType(IndraGitExtension.class)
if (!indraGit.isPresent()) {
return "detached-head"
}
Ref ref = indraGit.git().getRepository().exactRef('HEAD')?.target
if (ref == null) {
return "detached-head"
}
return Repository.shortenRefName(ref.name)
}
}

View File

@ -0,0 +1,5 @@
import org.gradle.api.Project
abstract class EssentialsModuleExtension(private val project: Project) {
val archiveFile = project.objects.fileProperty()
}

View File

@ -0,0 +1,18 @@
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
abstract class FileCopyTask : DefaultTask() {
@InputFile
val fileToCopy = project.objects.fileProperty()
@OutputFile
val destination = project.objects.fileProperty()
@TaskAction
private fun copyFile() {
destination.get().asFile.parentFile.mkdirs()
fileToCopy.get().asFile.copyTo(destination.get().asFile, overwrite = true)
}
}

View File

@ -0,0 +1 @@
const val RUN_PAPER_MINECRAFT_VERSION = "1.16.5"

View File

@ -0,0 +1,104 @@
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id("java")
id("net.kyori.indra")
id("net.kyori.indra.checkstyle")
id("net.kyori.indra.publishing")
}
val checkstyleVersion = "8.36.2"
val spigotVersion = "1.16.5-R0.1-SNAPSHOT"
val junit5Version = "5.7.0"
val mockitoVersion = "3.2.0"
dependencies {
testImplementation("org.junit.jupiter", "junit-jupiter", junit5Version)
testImplementation("org.junit.vintage", "junit-vintage-engine", junit5Version)
testImplementation("org.mockito", "mockito-core", mockitoVersion)
if (project.name != "1_8Provider" && project.name != "PaperProvider" && project.name != "NMSReflectionProvider") { // These providers use their own bukkit versions
api("org.spigotmc", "spigot-api", spigotVersion)
}
}
tasks {
// Version Injection
processResources {
// Always process resources if version string or git branch changes
val fullVersion = rootProject.ext["FULL_VERSION"] as String
val gitBranch = rootProject.ext["GIT_BRANCH"] as String
inputs.property("fullVersion", fullVersion)
inputs.property("gitBranch", gitBranch)
filter<ReplaceTokens>(
"beginToken" to "\${",
"endToken" to "}",
"tokens" to mapOf(
"full.version" to fullVersion,
"git.branch" to gitBranch
)
)
}
compileJava {
options.compilerArgs.add("-Xlint:-deprecation")
}
javadoc {
title = "${project.name} API (v${rootProject.ext["FULL_VERSION"]})"
val options = options as? StandardJavadocDocletOptions ?: return@javadoc
options.links(
"https://hub.spigotmc.org/javadocs/spigot/"
)
options.addBooleanOption("Xdoclint:none", true)
}
withType<Jar> {
archiveVersion.set(rootProject.ext["FULL_VERSION"] as String)
}
}
// Dependency caching
configurations.all {
resolutionStrategy.cacheChangingModulesFor(5, "minutes")
}
indra {
checkstyle(checkstyleVersion)
github("EssentialsX", "Essentials")
gpl3OnlyLicense()
publishReleasesTo("essx", "https://repo.essentialsx.net/releases/")
publishSnapshotsTo("essx", "https://repo.essentialsx.net/snapshots/")
configurePublications {
pom {
description.set("The essential plugin suite for Minecraft servers.")
url.set("https://essentialsx.net")
developers {
developer {
id.set("mdcfe")
name.set("MD")
email.set("md@n3fs.co.uk")
}
developer {
id.set("pop4959")
}
developer {
id.set("JRoy")
name.set("Josh Roy")
}
}
ciManagement {
system.set("Jenkins")
url.set("https://ci.ender.zone/job/EssentialsX")
}
}
}
javaVersions {
target(8)
minimumToolchain(16)
}
}
// undo https://github.com/KyoriPowered/indra/blob/master/indra-common/src/main/kotlin/net/kyori/indra/IndraPlugin.kt#L57
convention.getPlugin<BasePluginConvention>().archivesBaseName = project.name

View File

@ -0,0 +1,28 @@
plugins {
id("essentials.base-conventions")
id("xyz.jpenilla.run-paper")
}
val moduleExtension = extensions.create<EssentialsModuleExtension>("essentialsModule", project)
tasks {
runServer {
minecraftVersion(RUN_PAPER_MINECRAFT_VERSION)
runDirectory(rootProject.file("run"))
if (project.name != "EssentialsX") {
pluginJars.from(rootProject.project(":EssentialsX").the<EssentialsModuleExtension>().archiveFile)
}
}
jar {
moduleExtension.archiveFile.set(archiveFile)
}
val copyJar = register<FileCopyTask>("copyJar") {
fileToCopy.set(moduleExtension.archiveFile)
destination.set(rootProject.layout.projectDirectory.dir(provider { "jars" }).flatMap {
it.file(fileToCopy.map { file -> file.asFile.name })
})
}
build {
dependsOn(copyJar)
}
}

View File

@ -0,0 +1,52 @@
import xyz.jpenilla.runpaper.task.RunServerTask
plugins {
id("base")
id("net.kyori.indra.git")
id("xyz.jpenilla.run-paper")
}
runPaper {
disablePluginJarDetection()
}
val runModules = (findProperty("runModules") as String?)
?.trim()?.split(",") ?: emptySet()
tasks {
runServer {
// Enable modules for this task using the runModules property.
// Ex: './gradlew :runServer -PrunModules=chat,spawn'
minecraftVersion(RUN_PAPER_MINECRAFT_VERSION)
}
register<RunServerTask>("runAll") {
group = "essentials"
description = "Run a test server with all EssentialsX modules."
minecraftVersion(RUN_PAPER_MINECRAFT_VERSION)
}
named<Delete>("clean") {
delete(file("jars"))
}
}
subprojects {
afterEvaluate {
val moduleExt = extensions.findByType<EssentialsModuleExtension>() ?: return@afterEvaluate
rootProject.tasks.named<RunServerTask>("runAll").configure {
pluginJars.from(moduleExt.archiveFile)
}
if (name == "EssentialsX") {
rootProject.tasks.runServer.configure {
pluginJars.from(moduleExt.archiveFile)
}
return@afterEvaluate
}
for (module in runModules) {
if (name.contains(module, ignoreCase = true)) {
rootProject.tasks.runServer.configure {
pluginJars.from(moduleExt.archiveFile)
}
}
}
}
}

View File

@ -0,0 +1,17 @@
plugins {
id("essentials.module-conventions")
id("com.github.johnrengelman.shadow")
}
tasks {
jar {
archiveClassifier.set("unshaded")
}
shadowJar {
archiveClassifier.set(null)
}
}
extensions.configure<EssentialsModuleExtension> {
archiveFile.set(tasks.shadowJar.flatMap { it.archiveFile })
}

View File

@ -1,222 +1,14 @@
buildscript {
ext {
indraVersion = '2.0.4'
}
}
plugins { plugins {
id 'net.kyori.indra' version "$indraVersion" apply false id("essentials.parent-build-logic")
id 'net.kyori.indra.git' version "$indraVersion"
id 'net.kyori.indra.checkstyle' version "$indraVersion" apply false
id 'net.kyori.indra.publishing' version "$indraVersion" apply false
id 'com.github.johnrengelman.shadow' version '7.0.0' apply false
} }
import org.apache.tools.ant.filters.ReplaceTokens group = "net.essentialsx"
import org.eclipse.jgit.lib.Ref version = "2.19.0-SNAPSHOT"
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.revwalk.RevWalk
allprojects {
group = 'net.essentialsx'
version = '2.19.0-SNAPSHOT'
}
@SuppressWarnings('GrMethodMayBeStatic')
def commitsSinceLastTag() {
if (indraGit == null || !indraGit.isPresent() || indraGit.tags().isEmpty()) {
return -1
}
def tags = indraGit.tags()
def depth = 0
def walk = new RevWalk(indraGit.git().getRepository())
def commit = walk.parseCommit(indraGit.commit())
while (true) {
for (tag in tags) {
if (walk.parseCommit(tag.getLeaf().getObjectId()) == commit) {
walk.dispose()
indraGit.git().close()
return depth
}
}
depth++
commit = walk.parseCommit(commit.getParents()[0])
}
}
@SuppressWarnings('GrMethodMayBeStatic')
def headBranchName() {
if (System.getenv("GITHUB_HEAD_REF") != null && !System.getenv("GITHUB_HEAD_REF").isEmpty()) {
return System.getenv("GITHUB_HEAD_REF")
} else if (System.getenv("GITHUB_REF") != null && !System.getenv("GITHUB_REF").isEmpty()) {
return System.getenv("GITHUB_REF").replaceFirst("refs/heads/", "")
}
if (!indraGit.isPresent()) {
return "detached-head"
}
Ref ref = indraGit.git().getRepository().exactRef('HEAD')?.target
if (ref == null) {
return "detached-head"
}
return Repository.shortenRefName(ref.name)
}
project.ext { project.ext {
GIT_COMMIT = !indraGit.isPresent() ? "unknown" : indraGit.commit().abbreviate(7).name() GIT_COMMIT = !indraGit.isPresent() ? "unknown" : indraGit.commit().abbreviate(7).name()
GIT_DEPTH = commitsSinceLastTag() GIT_DEPTH = GitUtil.commitsSinceLastTag(project)
GIT_BRANCH = headBranchName() GIT_BRANCH = GitUtil.headBranchName(project)
fullVersion = "${version}".replace("-SNAPSHOT", "-dev+${GIT_DEPTH}-${GIT_COMMIT}") FULL_VERSION = "${version}".replace("-SNAPSHOT", "-dev+${GIT_DEPTH}-${GIT_COMMIT}")
checkstyleVersion = '8.36.2'
spigotVersion = '1.16.5-R0.1-SNAPSHOT'
junit5Version = '5.7.0'
mockitoVersion = '3.2.0'
}
subprojects {
apply plugin: 'java'
apply plugin: 'net.kyori.indra'
apply plugin: 'net.kyori.indra.checkstyle'
apply plugin: 'net.kyori.indra.publishing'
apply plugin: 'com.github.johnrengelman.shadow'
repositories {
maven { url = 'https://hub.spigotmc.org/nexus/content/groups/public/' }
maven { url = 'https://papermc.io/repo/repository/maven-public/' }
maven {
url = 'https://jitpack.io'
content {
includeGroup "com.github.milkbowl"
}
}
maven {
url = 'https://repo.codemc.org/repository/maven-public'
content {
includeGroup "org.bstats"
}
}
mavenCentral() {
content {
includeGroup "net.kyori"
}
}
}
dependencies {
testImplementation "org.junit.jupiter:junit-jupiter:${junit5Version}"
testImplementation "org.junit.vintage:junit-vintage-engine:${junit5Version}"
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
if (project.name != "1_8Provider" && project.name != "PaperProvider" && project.name != "NMSReflectionProvider") { // These providers use their own bukkit versions
api "org.spigotmc:spigot-api:${spigotVersion}"
}
}
// Dependency caching
configurations.all {
resolutionStrategy.cacheChangingModulesFor 5, 'minutes'
}
// Version Injection
processResources {
// Always process resources if version string or git branch changes
inputs.property('fullVersion', fullVersion)
inputs.property('gitBranch', GIT_BRANCH)
filter(ReplaceTokens, beginToken: '${',
endToken: '}', tokens: ["full.version": fullVersion, "git.branch": GIT_BRANCH])
}
indra {
checkstyle "$checkstyleVersion"
github('EssentialsX', 'Essentials')
gpl3OnlyLicense()
publishReleasesTo('essx', 'https://repo.essentialsx.net/releases/')
publishSnapshotsTo('essx', 'https://repo.essentialsx.net/snapshots/')
configurePublications {
pom {
description = 'The essential plugin suite for Minecraft servers.'
url = 'https://essentialsx.net'
developers {
developer {
id = 'mdcfe'
name = 'MD'
email = 'md@n3fs.co.uk'
}
developer {
id = 'pop4959'
}
developer {
id = 'JRoy'
name = 'Josh Roy'
}
}
ciManagement {
system = 'Jenkins'
url = 'https://ci.ender.zone/job/EssentialsX'
}
}
}
javaVersions {
target 8
minimumToolchain 16
}
}
compileJava {
options.compilerArgs.add('-Xlint:-deprecation')
}
javadoc {
title = "${project.name} API (v${rootProject.ext.fullVersion})"
options.links(
'https://hub.spigotmc.org/javadocs/spigot/'
)
options.addBooleanOption('Xdoclint:none', true)
}
// undo https://github.com/KyoriPowered/indra/blob/master/indra-common/src/main/kotlin/net/kyori/indra/IndraPlugin.kt#L57
archivesBaseName = project.name
tasks.withType(Jar) {
archiveVersion.set(fullVersion)
}
}
def outputTasks() {
[":EssentialsX:shadowJar", ":EssentialsXAntiBuild:jar", ":EssentialsXChat:jar",
":EssentialsXGeoIP:shadowJar", ":EssentialsXProtect:jar", ":EssentialsXSpawn:jar",
":EssentialsXXMPP:shadowJar"].stream().map({ tasks.findByPath(it) })
}
task copyToJars(type: Copy) {
dependsOn tasks.findByPath(":EssentialsX:processResources")
outputTasks().forEach {
from(it)
}
rename '(.*)-all.jar', '$1.jar'
into file('jars')
}
task cleanJars() {
delete file('jars')
}
task clean() {
dependsOn cleanJars
}
task build() {
dependsOn copyToJars
} }

View File

@ -1,3 +1,7 @@
plugins {
id("essentials.base-conventions")
}
dependencies { dependencies {
api project(':providers:NMSReflectionProvider') api project(':providers:NMSReflectionProvider')
} }

View File

@ -0,0 +1,3 @@
plugins {
id("essentials.base-conventions")
}

View File

@ -1,3 +1,7 @@
plugins {
id("essentials.base-conventions")
}
dependencies { dependencies {
implementation project(':providers:BaseProviders') implementation project(':providers:BaseProviders')
api 'org.bukkit:bukkit:1.12.2-R0.1-SNAPSHOT' api 'org.bukkit:bukkit:1.12.2-R0.1-SNAPSHOT'

View File

@ -1,3 +1,7 @@
plugins {
id("essentials.base-conventions")
}
dependencies { dependencies {
implementation project(':providers:BaseProviders') implementation project(':providers:BaseProviders')
compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT' compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'

View File

@ -1,21 +0,0 @@
rootProject.name = 'EssentialsXParent'
// Modules
[
"",
"AntiBuild",
"Chat",
"GeoIP",
"Protect",
"Spawn",
"XMPP",
].each {
include(":EssentialsX$it")
project(":EssentialsX$it").projectDir = file("Essentials$it")
}
// Providers
include(':providers:BaseProviders')
include(':providers:NMSReflectionProvider')
include(':providers:PaperProvider')
include(':providers:1_8Provider')

42
settings.gradle.kts Normal file
View File

@ -0,0 +1,42 @@
dependencyResolutionManagement {
repositories {
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://jitpack.io") {
content { includeGroup("com.github.milkbowl") }
}
maven("https://repo.codemc.org/repository/maven-public") {
content { includeGroup("org.bstats") }
}
mavenCentral {
content { includeGroup("net.kyori") }
}
}
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
}
pluginManagement {
includeBuild("build-logic")
}
rootProject.name = "EssentialsXParent"
// Modules
sequenceOf(
"",
"AntiBuild",
"Chat",
"GeoIP",
"Protect",
"Spawn",
"XMPP",
).forEach {
include(":EssentialsX$it")
project(":EssentialsX$it").projectDir = file("Essentials$it")
}
// Providers
include(":providers:BaseProviders")
include(":providers:NMSReflectionProvider")
include(":providers:PaperProvider")
include(":providers:1_8Provider")