perf: 优化代码

This commit is contained in:
2023-06-14 20:22:01 +08:00
parent 31510cf599
commit 57357c6ae2
5 changed files with 60 additions and 121 deletions

View File

@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx2G org.gradle.jvmargs=-Xmx2G
adventure_version=4.3.0 adventure_version=4.3.0
adventure_serializer_version=4.13.0 adventure_serializer_version=4.13.0
HikariCP_version=5.0.1 HikariCP_version=4.0.3

View File

@@ -1,93 +1,62 @@
//file:noinspection GroovyAssignabilityCheck //file:noinspection GroovyAssignabilityCheck
//file:noinspection VulnerableLibrariesLocal
//file:noinspection GrDeprecatedAPIUsage
plugins { plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2' id 'com.github.johnrengelman.shadow' version '7+'
} }
setArchivesBaseName("HamsterCore-Bukkit") setArchivesBaseName("HamsterCore-Bukkit")
evaluationDependsOn(':hamster-core-common') evaluationDependsOn(':hamster-core-common')
configurations {
oldJar
}
dependencies { dependencies {
implementation "de.tr7zw:item-nbt-api:2.11.2"
//noinspection VulnerableLibrariesLocal //noinspection VulnerableLibrariesLocal
compileOnly 'org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT' exclude group: "com.google.code.gson" compileOnly 'org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT'
compileOnly 'net.milkbowl.vault:VaultAPI:1.7' transitive false compileOnly 'net.milkbowl.vault:VaultAPI:1.7' transitive false
compileOnly 'org.black_ixx:playerpoints:2.1.3' transitive false compileOnly 'org.black_ixx:playerpoints:2.1.3' transitive false
api project(":hamster-core-common") transitive false implementation project(":hamster-core-common") transitive false
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-bukkit
api "net.kyori:adventure-platform-bukkit:${adventure_version}"
// https://mvnrepository.com/artifact/net.kyori/adventure-text-minimessage
api "net.kyori:adventure-text-minimessage:${adventure_serializer_version}"
// https://mvnrepository.com/artifact/net.kyori/adventure-text-serializer-gson
api "net.kyori:adventure-text-serializer-gson:${adventure_serializer_version}"
// https://mvnrepository.com/artifact/net.kyori/adventure-text-serializer-legacy
api "net.kyori:adventure-text-serializer-legacy:${adventure_serializer_version}"
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
compileOnly "com.zaxxer:HikariCP:${HikariCP_version}"
//noinspection GradlePackageUpdate //noinspection GradlePackageUpdate
oldJar 'com.zaxxer:HikariCP:4.0.3' implementation "com.zaxxer:HikariCP:${HikariCP_version}"
//noinspection VulnerableLibrariesLocal //noinspection VulnerableLibrariesLocal
oldJar "net.kyori:adventure-platform-bukkit:${adventure_version}" implementation "net.kyori:adventure-platform-bukkit:${adventure_version}" exclude group: 'org.jetbrains'
// https://mvnrepository.com/artifact/net.kyori/adventure-text-minimessage
implementation "net.kyori:adventure-text-minimessage:${adventure_serializer_version}" exclude group: 'org.jetbrains'
// https://mvnrepository.com/artifact/net.kyori/adventure-text-serializer-gson
implementation "net.kyori:adventure-text-serializer-gson:${adventure_serializer_version}" exclude group: 'org.jetbrains'
// https://mvnrepository.com/artifact/net.kyori/adventure-text-serializer-legacy
implementation "net.kyori:adventure-text-serializer-legacy:${adventure_serializer_version}" exclude group: 'org.jetbrains'
implementation "de.tr7zw:item-nbt-api:2.11.2"
} }
processResources { processResources {
inputs.property "version", project.version inputs.property "version", project.version
filesMatching("plugin.yml") { filesMatching("plugin.yml") {
expand "version": project.version, expand "version": project.version
"adventure_version": adventure_version,
"adventure_serializer_version": adventure_serializer_version,
"HikariCP_version": HikariCP_version
} }
} }
jar { jar {
//noinspection GrDeprecatedAPIUsage classifier = 'dev'
classifier = "jar"
} }
tasks.compileJava.dependsOn(":hamster-core-common:build") tasks.compileJava.dependsOn(":hamster-core-common:build")
shadowJar { shadowJar {
//noinspection GrDeprecatedAPIUsage classifier = ''
classifier = ""
dependencies { dependencies {
exclude(dependency { exclude(dependency {
it.moduleGroup != 'cn.hamster3.mc.plugin.core' && it.moduleGroup != 'de.tr7zw' it.moduleGroup == 'com.google.code.gson' || it.moduleName == 'org.jetbrains'
}) })
} }
relocate 'de.tr7zw.changeme.nbtapi', 'cn.hamster3.mc.plugin.core.bukkit.nbtapi' relocate 'org.slf4j', 'cn.hamster3.mc.plugin.core.lib.slf4j'
relocate 'de.tr7zw.annotations', 'cn.hamster3.mc.plugin.core.bukkit.nbtapi.annotations' relocate 'net.kyori', 'cn.hamster3.mc.plugin.core.lib.kyori'
relocate 'com.zaxxer.hikari', 'cn.hamster3.mc.plugin.core.lib.hikari'
relocate 'de.tr7zw.changeme.nbtapi', 'cn.hamster3.mc.plugin.core.lib.nbtapi'
relocate 'de.tr7zw.annotations', 'cn.hamster3.mc.plugin.core.lib.nbtapi.annotations'
destinationDir(getRootProject().buildDir) destinationDir(getRootProject().buildDir)
} }
tasks.build.dependsOn(shadowJar) tasks.build.dependsOn(shadowJar)
tasks.register("oldJar", Jar) {
dependsOn("jar")
//noinspection GrDeprecatedAPIUsage
setClassifier("Old")
from([
tasks.jar.outputs.files.collect {
it.isDirectory() ? it : zipTree(it)
},
configurations.shade.collect {
it.isDirectory() ? it : zipTree(it)
},
configurations.oldJar.collect {
it.isDirectory() ? it : zipTree(it)
}
])
destinationDir(getRootProject().buildDir)
}
tasks.build.dependsOn(oldJar)
publishing { publishing {
publications { publications {
shadow(MavenPublication) { publication -> shadow(MavenPublication) { publication ->

View File

@@ -16,14 +16,6 @@ softdepend:
loadbefore: loadbefore:
- HamsterAPI - HamsterAPI
libraries:
- 'net.kyori:adventure-platform-bukkit:${adventure_version}'
- 'net.kyori:adventure-text-minimessage:${adventure_serializer_version}'
- 'net.kyori:adventure-text-serializer-gson:${adventure_serializer_version}'
- 'net.kyori:adventure-text-serializer-legacy:${adventure_serializer_version}'
- 'com.squareup.okhttp3:okhttp:4.10.0'
- 'com.zaxxer:HikariCP:5.0.1'
commands: commands:
hamster-core: hamster-core:
aliases: [ hcore, hc, core ] aliases: [ hcore, hc, core ]

View File

@@ -1,35 +1,28 @@
//file:noinspection GroovyAssignabilityCheck //file:noinspection GroovyAssignabilityCheck
//file:noinspection VulnerableLibrariesLocal
//file:noinspection GrDeprecatedAPIUsage
plugins {
id 'com.github.johnrengelman.shadow' version '7+'
}
setArchivesBaseName("HamsterCore-BungeeCord") setArchivesBaseName("HamsterCore-BungeeCord")
evaluationDependsOn(':hamster-core-common') evaluationDependsOn(':hamster-core-common')
configurations {
oldJar
}
dependencies { dependencies {
api project(":hamster-core-common") transitive false
shade project(":hamster-core-common") transitive false
oldJar project(":hamster-core-common") transitive false
//noinspection VulnerableLibrariesLocal //noinspection VulnerableLibrariesLocal
compileOnly 'net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT' compileOnly 'net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT'
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-bungeecord implementation project(":hamster-core-common") transitive false
api "net.kyori:adventure-platform-bungeecord:${adventure_version}"
shade "net.kyori:adventure-platform-bungeecord:${adventure_version}"
oldJar "net.kyori:adventure-platform-bungeecord:${adventure_version}"
// // https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
// api 'com.squareup.okhttp3:okhttp:4.10.0'
// shade 'com.squareup.okhttp3:okhttp:4.10.0'
// oldJar 'com.squareup.okhttp3:okhttp:4.10.0'
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
compileOnly 'com.zaxxer:HikariCP:5.0.1'
shade 'com.zaxxer:HikariCP:5.0.1'
//noinspection GradlePackageUpdate //noinspection GradlePackageUpdate
oldJar 'com.zaxxer:HikariCP:4.0.3' exclude group: "org.slf4j" implementation "com.zaxxer:HikariCP:${HikariCP_version}"
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-bungeecord
implementation "net.kyori:adventure-platform-bungeecord:${adventure_version}" exclude group: 'org.jetbrains'
// https://mvnrepository.com/artifact/net.kyori/adventure-text-minimessage
implementation "net.kyori:adventure-text-minimessage:${adventure_serializer_version}" exclude group: 'org.jetbrains'
// https://mvnrepository.com/artifact/net.kyori/adventure-text-serializer-gson
implementation "net.kyori:adventure-text-serializer-gson:${adventure_serializer_version}" exclude group: 'org.jetbrains'
// https://mvnrepository.com/artifact/net.kyori/adventure-text-serializer-legacy
implementation "net.kyori:adventure-text-serializer-legacy:${adventure_serializer_version}" exclude group: 'org.jetbrains'
} }
processResources { processResources {
@@ -39,44 +32,33 @@ processResources {
} }
} }
jar {
classifier = 'dev'
}
tasks.compileJava.dependsOn(":hamster-core-common:build") tasks.compileJava.dependsOn(":hamster-core-common:build")
tasks.register("shadowJar", Jar) { shadowJar {
dependsOn("jar") classifier = ''
from([ dependencies {
tasks.jar.outputs.files.collect { exclude(dependency {
it.isDirectory() ? it : zipTree(it) it.moduleGroup == 'com.google.code.gson' || it.moduleName == 'org.jetbrains'
}, })
configurations.shade.collect { }
it.isDirectory() ? it : zipTree(it) relocate 'org.slf4j', 'cn.hamster3.mc.plugin.core.lib.slf4j'
} relocate 'net.kyori', 'cn.hamster3.mc.plugin.core.lib.kyori'
]) relocate 'com.zaxxer.hikari', 'cn.hamster3.mc.plugin.core.lib.hikari'
destinationDir(getRootProject().buildDir) destinationDir(getRootProject().buildDir)
} }
tasks.build.dependsOn(shadowJar) tasks.build.dependsOn(shadowJar)
tasks.register("oldJar", Jar) {
dependsOn("jar")
//noinspection GrDeprecatedAPIUsage
setClassifier("Old")
from([
tasks.jar.outputs.files.collect {
it.isDirectory() ? it : zipTree(it)
},
configurations.oldJar.collect {
it.isDirectory() ? it : zipTree(it)
}
])
destinationDir(getRootProject().buildDir)
}
tasks.build.dependsOn(oldJar)
publishing { publishing {
publications { publications {
mavenJava(MavenPublication) { shadow(MavenPublication) { publication ->
def projectNameSplit = project.name.split('-') {
artifactId = projectNameSplit[projectNameSplit.length - 1] def projectNameSplit = project.name.split('-')
from project.components.java artifactId = projectNameSplit[projectNameSplit.length - 1]
from components.java
}
} }
} }
repositories { repositories {

View File

@@ -7,14 +7,10 @@ dependencies {
//noinspection VulnerableLibrariesLocal //noinspection VulnerableLibrariesLocal
compileOnly 'com.google.code.gson:gson:2.8.0' compileOnly 'com.google.code.gson:gson:2.8.0'
// https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
compileOnly 'com.squareup.okhttp3:okhttp:4.10.0'
// https://mvnrepository.com/artifact/net.kyori/adventure-api // https://mvnrepository.com/artifact/net.kyori/adventure-api
compileOnly 'net.kyori:adventure-api:${adventure_version}' compileOnly "net.kyori:adventure-api:${adventure_version}"
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-api // https://mvnrepository.com/artifact/net.kyori/adventure-platform-api
compileOnly "net.kyori:adventure-platform-api:${adventure_version}" compileOnly "net.kyori:adventure-platform-api:${adventure_version}"
// https://mvnrepository.com/artifact/net.kyori/adventure-text-minimessage // https://mvnrepository.com/artifact/net.kyori/adventure-text-minimessage
compileOnly "net.kyori:adventure-text-minimessage:${adventure_serializer_version}" compileOnly "net.kyori:adventure-text-minimessage:${adventure_serializer_version}"
// https://mvnrepository.com/artifact/net.kyori/adventure-text-serializer-gson // https://mvnrepository.com/artifact/net.kyori/adventure-text-serializer-gson