131 lines
4.3 KiB
Groovy
131 lines
4.3 KiB
Groovy
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
|
import org.gradle.language.jvm.tasks.ProcessResources
|
|
import org.gradle.api.tasks.testing.Test
|
|
import java.util.zip.ZipFile
|
|
|
|
plugins {
|
|
id 'java'
|
|
id 'io.papermc.paperweight.userdev' version '2.0.0-beta.21'
|
|
id 'com.gradleup.shadow' version '8.3.11'
|
|
}
|
|
|
|
group = 'cn.infstar'
|
|
def pluginVersion = providers.gradleProperty('pluginVersion').orElse('1.3.1').get()
|
|
version = pluginVersion
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
maven {
|
|
name = 'papermc'
|
|
url = uri('https://repo.papermc.io/repository/maven-public/')
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
paperweight.paperDevBundle('1.21.11-R0.1-SNAPSHOT')
|
|
implementation 'com.google.code.gson:gson:2.11.0'
|
|
testImplementation platform('org.junit:junit-bom:5.13.4')
|
|
testImplementation 'org.junit.jupiter:junit-jupiter'
|
|
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
|
}
|
|
|
|
java {
|
|
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
|
}
|
|
|
|
paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.getMOJANG_PRODUCTION()
|
|
|
|
allprojects {
|
|
tasks.withType(JavaCompile).configureEach {
|
|
options.encoding = 'UTF-8'
|
|
options.compilerArgs.addAll(['-Xlint:deprecation', '-Werror'])
|
|
}
|
|
}
|
|
|
|
tasks.withType(ProcessResources).configureEach {
|
|
filteringCharset = 'UTF-8'
|
|
}
|
|
|
|
tasks.withType(Test).configureEach {
|
|
useJUnitPlatform()
|
|
}
|
|
|
|
tasks.named('processResources', ProcessResources).configure {
|
|
inputs.property('version', pluginVersion)
|
|
filesMatching('paper-plugin.yml') {
|
|
expand('version': pluginVersion)
|
|
}
|
|
}
|
|
|
|
tasks.named('jar').configure {
|
|
enabled = false
|
|
}
|
|
|
|
tasks.named('shadowJar', ShadowJar).configure {
|
|
group = 'build'
|
|
description = '构建包含全部运行期可开关模块的 EssentialsC 插件。'
|
|
archiveFileName.set("EssentialsC-${pluginVersion}.jar")
|
|
configurations = [project.configurations.runtimeClasspath]
|
|
relocate 'com.google.gson', 'cn.infstar.essentialsC.libs.gson'
|
|
}
|
|
|
|
tasks.named('assemble').configure {
|
|
dependsOn(tasks.named('shadowJar'))
|
|
}
|
|
|
|
tasks.register('verifyJava21Bytecode') {
|
|
group = 'verification'
|
|
description = '验证最终插件中的全部 class 均可由 Java 21 加载。'
|
|
dependsOn(tasks.named('shadowJar'))
|
|
|
|
doLast {
|
|
def artifact = tasks.named('shadowJar', ShadowJar).get().archiveFile.get().asFile
|
|
def unsupportedClasses = []
|
|
new ZipFile(artifact).withCloseable { zip ->
|
|
zip.entries().each { entry ->
|
|
if (!entry.directory && entry.name.endsWith('.class')) {
|
|
zip.getInputStream(entry).withCloseable { input ->
|
|
byte[] header = input.readNBytes(8)
|
|
if (header.length == 8) {
|
|
int majorVersion = ((header[6] & 0xff) << 8) | (header[7] & 0xff)
|
|
if (majorVersion > 65) {
|
|
unsupportedClasses.add("${entry.name} (class ${majorVersion})")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!unsupportedClasses.isEmpty()) {
|
|
throw new GradleException("检测到无法由 Java 21 加载的类:\n" + unsupportedClasses.join('\n'))
|
|
}
|
|
}
|
|
}
|
|
|
|
tasks.named('check').configure {
|
|
dependsOn(tasks.named('verifyJava21Bytecode'))
|
|
}
|
|
|
|
def registerTestServerDeployTask = { String taskName, String serverPath, String serverName ->
|
|
tasks.register(taskName, Copy) {
|
|
group = 'deployment'
|
|
description = "构建并部署插件到本地 ${serverName} 测试服务器。"
|
|
def artifact = tasks.named('shadowJar').flatMap { it.archiveFile }
|
|
def pluginsDir = layout.projectDirectory.dir("${serverPath}/plugins")
|
|
dependsOn(tasks.named('shadowJar'))
|
|
from(artifact)
|
|
into(pluginsDir)
|
|
|
|
doFirst {
|
|
delete(fileTree(pluginsDir) {
|
|
include 'EssentialsC*.jar'
|
|
})
|
|
delete(pluginsDir.file('EssentialsC').asFile)
|
|
}
|
|
}
|
|
}
|
|
|
|
registerTestServerDeployTask('deployToPaper12111', 'test-server/paper-1.21.11', 'Paper 1.21.11')
|
|
registerTestServerDeployTask('deployToPaper262', 'test-server/paper-26.2', 'Paper 26.2')
|
|
registerTestServerDeployTask('deployToLeaves262', 'test-server/leaves-26.2', 'Leaves 26.2')
|