Skip to content

Commit

Permalink
Remove Spigradle (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
turikhay authored Jan 10, 2024
1 parent da2b389 commit 51680ab
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 44 deletions.
5 changes: 5 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ dependencies {
// See https://github.com/gradle/gradle/issues/15383
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(with(libs.plugins.shadow.get()) { "com.github.johnrengelman:shadow:$version" })
with(libs.versions.jackson) {
val version = get()
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$version")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:$version")
}
}
76 changes: 76 additions & 0 deletions buildSrc/src/main/kotlin/PluginDescriptor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import com.fasterxml.jackson.core.JsonFactory
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import com.fasterxml.jackson.module.kotlin.readValue
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import org.gradle.api.DefaultTask
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import java.io.File

enum class PluginDescriptorFormat {
YAML, JSON
}

abstract class PluginDescriptorTask : DefaultTask() {

@get:Input
@get:Optional
abstract val descriptor: Property<String>

@get:InputFile
@get:Optional
abstract val descriptorFile: RegularFileProperty

@get:Input
abstract val content: MapProperty<String, Any>

@get:Input
@get:Optional
abstract val format: Property<PluginDescriptorFormat>

@get:Input
@get:Optional
abstract val append: Property<Boolean>

init {
project.tasks.getByName("processResources") {
finalizedBy(this@PluginDescriptorTask)
}
}

@TaskAction
fun writeFile() {
val mapper = constructMapper()
mapper.registerKotlinModule()
val file = extractDescriptorFile()
val fileContent = LinkedHashMap<String, Any>()
if (append.getOrElse(false)) {
fileContent.putAll(mapper.readValue<Map<String, Any>>(file))
}
fileContent.putAll(content.get())
mapper.writeValue(
file,
fileContent,
)
}

private fun constructMapper(): ObjectMapper {
@Suppress("WHEN_ENUM_CAN_BE_NULL_IN_JAVA")
return ObjectMapper(when(format.getOrElse(PluginDescriptorFormat.YAML)) {
PluginDescriptorFormat.JSON -> JsonFactory()
PluginDescriptorFormat.YAML -> YAMLFactory()
})
}

private fun extractDescriptorFile(): File {
var file: File? = descriptorFile.map { it.asFile }.orNull
if (file == null) {
val sourceSets: SourceSetContainer = project.extensions.getByName("sourceSets") as SourceSetContainer
file = sourceSets.getByName("main").output.resourcesDir!!.resolve(descriptor.get())
}
return file
}
}
26 changes: 17 additions & 9 deletions bungee/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
import kr.entree.spigradle.kotlin.bungeecord

plugins {
id("java-shadow")
alias(libs.plugins.spigradle.bungee)
}

bungee {
name = "MapModCompanion"
author = "turikhay"
debug {
jvmArgs = listOf("-Xmx256m", "-Dnet.md_5.bungee.console-log-level=ALL")
repositories {
maven {
name = "Sonatype"
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
}

tasks {
val writeBungeeYml by creating(PluginDescriptorTask::class) {
descriptor = "bungee.yml"
content.putAll(mapOf(
"name" to "MapModCompanion",
"version" to project.version,
"author" to "turikhay",
"main" to "com.turikhay.mc.mapmodcompanion.bungee.MapModCompanion"
))
}
}

dependencies {
implementation(project(":common"))
implementation(libs.bstats.bungeecord)
compileOnly(bungeecord())
compileOnly("net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT")
}
4 changes: 1 addition & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
spigradle = "2.4.3"
spotbugs = "4.8.3"
shadow = "8.1.1"
junit = "5.10.1"
bstats = "3.0.2"
velocity-api = "3.1.1"
jackson = "2.16.1"

[libraries]
spotbugs-annotations = { module = "com.github.spotbugs:spotbugs-annotations", version.ref = "spotbugs" }
Expand All @@ -17,6 +17,4 @@ velocity-api = { module = "com.velocitypowered:velocity-api", version.ref = "vel


[plugins]
spigradle = { id = "kr.entree.spigradle", version.ref = "spigradle" }
spigradle-bungee = { id = "kr.entree.spigradle.bungee", version.ref = "spigradle" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
39 changes: 18 additions & 21 deletions spigot/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
import kr.entree.spigradle.kotlin.spigot

plugins {
id("java-shadow")
alias(libs.plugins.spigradle)
}

repositories {
maven {
url = uri("https://repo.dmulloy2.net/repository/public/")
}
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
maven {
url = uri("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
}
}

val bStats = with(libs.bstats.bukkit.get()) { "$module:$versionConstraint" }

spigot {
name = "MapModCompanion"
authors = listOf("turikhay")
apiVersion = "1.13"
softDepends = listOf("ProtocolLib")
debug {
jvmArgs = listOf(
"-Xmx2048m",
"-Dlog4j.configurationFile=${projectDir}${File.separatorChar}log4j2-debug.xml",
"-Dcom.turikhay.mc.mapmodcompanion.spigot.debug=true"
)
}
afterEvaluate {
excludeLibraries = listOf(
rootProject.allprojects.map { "${it.group}:${it.name}:${it.version}" },
listOf(bStats)
).flatten()
tasks {
val writePluginYml by creating(PluginDescriptorTask::class) {
descriptor = "plugin.yml"
content.putAll(mapOf(
"name" to "MapModCompanion",
"version" to project.version,
"authors" to listOf("turikhay"),
"apiVersion" to "1.13",
"softDepends" to listOf("ProtocolLib"),
"main" to "com.turikhay.mc.mapmodcompanion.spigot.MapModCompanion"
))
}
}

Expand All @@ -42,6 +39,6 @@ dependencies {
implementation(libs.bstats.bukkit)

// These dependencies are intentionally not present in libs.version.toml
compileOnly(spigot(spigot_version))
compileOnly("org.spigotmc:spigot-api:${spigot_version}-R0.1-SNAPSHOT")
compileOnly("com.comphenix.protocol:ProtocolLib:${protocolLib_version}")
}
19 changes: 8 additions & 11 deletions velocity/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import groovy.json.JsonSlurper
import groovy.json.JsonOutput

plugins {
id("java-shadow")
}
Expand All @@ -26,14 +23,14 @@ dependencies {
}

tasks {
classes {
doLast {
val pluginFile = project.layout.buildDirectory.file("classes/java/main/velocity-plugin.json").get().getAsFile()
@Suppress("UNCHECKED_CAST")
val pluginDescriptor = JsonSlurper().parse(pluginFile) as MutableMap<String, Any>
pluginDescriptor["version"] = version
pluginFile.writeText(JsonOutput.toJson(pluginDescriptor))
}
val rewriteVelocityPluginJson by creating(PluginDescriptorTask::class) {
dependsOn(compileJava)
descriptorFile = project.layout.buildDirectory.file("classes/java/main/velocity-plugin.json")
format = PluginDescriptorFormat.JSON
append = true
content.putAll(mapOf(
"version" to project.version
))
}

shadowJar {
Expand Down

0 comments on commit 51680ab

Please sign in to comment.