feat(utils): 添加通用工具类和 Minecraft SLA 功能
- 新增 Collection 工具类,提供集合操作方法 - 新增 ComponentBean 注解,用于组件标识- 新增 DateTime、DateTimeOffset 和 DateTimeUnit 类,提供时间处理功能 - 新增 Debouncer 类,实现防抖功能 - 新增 Minecraft SLA 相关类,包括 Description 和 Extra - 更新 .gitattributes,添加 PNG 文件的二进制处理 - 更新 .gitignore,排除 Idea 项目图标- 重构 build.gradle.kts,优化项目构建配置
This commit is contained in:
+34
-121
@@ -1,164 +1,77 @@
|
||||
import java.security.MessageDigest
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
|
||||
plugins {
|
||||
id("java")
|
||||
idea
|
||||
id("java-library")
|
||||
id("maven-publish")
|
||||
id("com.github.johnrengelman.shadow") version ("8.1.1")
|
||||
}
|
||||
|
||||
val GROUPSID = project.properties["GROUPSID"] as String
|
||||
val VERSIONS = project.properties["VERSIONS"] as String
|
||||
val ARTIFACTID = project.properties["ARTIFACTID"] as String
|
||||
val MAINCLASS = project.properties["MAINCLASS"] as String
|
||||
val buildTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())
|
||||
|
||||
val jarNameStr = "${ARTIFACTID}-${VERSIONS}"
|
||||
val jarName = "${jarNameStr}.jar"
|
||||
val srcJarName = "${jarNameStr}-sources.jar"
|
||||
val fatJarName = "${jarNameStr}-all.jar"
|
||||
group = GROUPSID
|
||||
version = VERSIONS
|
||||
|
||||
val libDir = rootDir.resolve("build").resolve("libs")
|
||||
val publicationsDir =
|
||||
rootDir.resolve("build").resolve("publications").resolve("mavenJava")
|
||||
base {
|
||||
archivesName.set(ARTIFACTID)
|
||||
}
|
||||
|
||||
java {
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
compileOnly("org.springframework.boot:spring-boot-starter:2.7.14")
|
||||
compileOnly("com.fasterxml.jackson.core:jackson-databind:2.19.2")
|
||||
compileOnly("org.mybatis:mybatis:3.5.19")
|
||||
|
||||
implementation("org.bouncycastle:bcprov-jdk18on:1.81")
|
||||
implementation("com.github.f4b6a3:uuid-creator:6.1.0")
|
||||
implementation("org.mindrot:jbcrypt:0.4")
|
||||
implementation("org.jetbrains:annotations:24.0.0")
|
||||
compileOnly("org.projectlombok:lombok:1.18.38")
|
||||
|
||||
annotationProcessor("org.jetbrains:annotations:24.0.0")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
private fun generateHash(file: File, string: String): String {
|
||||
val md = MessageDigest.getInstance(string)
|
||||
file.forEachBlock(4096) { bytes, size ->
|
||||
md.update(bytes, 0, size)
|
||||
}
|
||||
return md.digest().joinToString("") {
|
||||
"%02x".format(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getHash(outpath: String, file: File) {
|
||||
val md5 = generateHash(file, "MD5")
|
||||
val sha1 = generateHash(file, "SHA-1")
|
||||
val sha256 = generateHash(file, "SHA-256")
|
||||
val sha512 = generateHash(file, "SHA-512")
|
||||
val md5f = File(outpath, file.getName() + ".md5")
|
||||
val sha1f = File(outpath, file.getName() + ".sha1")
|
||||
val sha256f = File(outpath, file.getName() + ".sha256")
|
||||
val sha512f = File(outpath, file.getName() + ".sha512")
|
||||
md5f.writeText(md5)
|
||||
sha1f.writeText(sha1)
|
||||
sha256f.writeText(sha256)
|
||||
sha512f.writeText(sha512)
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.38")
|
||||
}
|
||||
|
||||
|
||||
sourceSets.main.configure {
|
||||
java.setSrcDirs(files("src"))
|
||||
resources.setSrcDirs(files("resources"))
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
archiveFileName.set(fatJarName)
|
||||
archiveClassifier.set("all")
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
from(sourceSets.main.get().output) // 编译输出
|
||||
from(project.configurations.runtimeClasspath) // 运行时依赖
|
||||
from("src/main/resources") { // 资源文件
|
||||
into(".")
|
||||
}
|
||||
manifest {
|
||||
attributes["Main-Class"] = MAINCLASS
|
||||
attributes["Implementation-GroupId"] = GROUPSID
|
||||
attributes["Implementation-ArtifactId"] = ARTIFACTID
|
||||
attributes["Implementation-Version"] = VERSIONS
|
||||
attributes["Email"] = "minglipro@163.com"
|
||||
attributes["Implementation-Vendor"] = "minglipro|Armamem0t"
|
||||
attributes["Copyright"] =
|
||||
"Copyright 2026 minglipro All rights reserved."
|
||||
attributes["Env"] = "prod"
|
||||
attributes["LICENSE"] = "Apache License 2.0"
|
||||
attributes["Created"] = "2025-06-26 09:13:51"
|
||||
attributes["Updated"] = buildTime
|
||||
}
|
||||
mergeServiceFiles()
|
||||
exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA") // 排除签名文件
|
||||
from("LICENSE")
|
||||
into(".")
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
tasks.withType<JavaExec>().configureEach {
|
||||
jvmArgs = listOf(
|
||||
"-Dfile.encoding=UTF-8",
|
||||
"-Dsun.stdout.encoding=UTF-8",
|
||||
"-Dsun.stderr.encoding=UTF-8"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
tasks.jar {
|
||||
archiveFileName.set(jarName)
|
||||
doFirst {
|
||||
delete(libDir)
|
||||
mkdir(libDir)
|
||||
}
|
||||
manifest {
|
||||
attributes["Main-Class"] = MAINCLASS
|
||||
attributes["Implementation-GroupId"] = GROUPSID
|
||||
attributes["Implementation-ArtifactId"] = ARTIFACTID
|
||||
attributes["Implementation-Version"] = VERSIONS
|
||||
attributes["Email"] = "minglipro@163.com"
|
||||
attributes["Implementation-Vendor"] = "minglipro|Armamem0t"
|
||||
attributes["Copyright"] =
|
||||
"Copyright 2026 minglipro All rights reserved."
|
||||
attributes["Env"] = "prod"
|
||||
attributes["LICENSE"] = "Apache License 2.0"
|
||||
attributes["Created"] = "2025-06-26 09:13:51"
|
||||
attributes["Updated"] = buildTime
|
||||
}
|
||||
from("LICENSE")
|
||||
into(".")
|
||||
}
|
||||
tasks.register("build-jar") {
|
||||
dependsOn(tasks.jar)
|
||||
dependsOn(tasks.shadowJar)
|
||||
dependsOn(tasks["sourcesJar"])
|
||||
dependsOn(tasks["generatePomFileForMavenJavaPublication"])
|
||||
dependsOn(tasks["generateMetadataFileForMavenJavaPublication"])
|
||||
doLast {
|
||||
getHash(libDir.toString(),File(libDir, jarName))
|
||||
getHash(libDir.toString(),File(libDir, fatJarName))
|
||||
getHash(libDir.toString(),File(libDir, srcJarName))
|
||||
getHash(publicationsDir.toString(),File(publicationsDir, "module.json"))
|
||||
getHash(publicationsDir.toString(),File(publicationsDir, "pom-default.xml"))
|
||||
}
|
||||
}
|
||||
components {
|
||||
withType<AdhocComponentWithVariants>().configureEach {
|
||||
withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) {
|
||||
skip()
|
||||
}
|
||||
}
|
||||
tasks.withType<Javadoc> {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
name = "localMaven"
|
||||
url = uri("D:/git/maven-repository-raw")
|
||||
}
|
||||
}
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
from(components["java"])
|
||||
artifact(tasks.shadowJar.get())
|
||||
groupId = GROUPSID
|
||||
artifactId = ARTIFACTID
|
||||
version = VERSIONS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user