105 lines
3.1 KiB
Plaintext
105 lines
3.1 KiB
Plaintext
import java.security.MessageDigest
|
|
import java.text.SimpleDateFormat
|
|
import java.util.Date
|
|
|
|
plugins {
|
|
java
|
|
id("org.springframework.boot") version "3.5.3"
|
|
id("io.spring.dependency-management") version "1.1.7"
|
|
}
|
|
val GROUPSID = project.properties["GROUPSID"] as String
|
|
val VERSIONS = project.properties["VERSIONS"] as String
|
|
val ARTIFACTID = project.properties["ARTIFACTID"] 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 webZipName = "${jarNameStr}-web.zip"
|
|
group = GROUPSID
|
|
version = VERSIONS
|
|
|
|
val libDir = rootDir.resolve("build").resolve("libs")
|
|
val srcDir = rootDir.resolve("src").resolve("main").resolve("java")
|
|
val webDir = rootDir.resolve("src").resolve("main").resolve("resources").resolve("static")
|
|
java {
|
|
toolchain {
|
|
languageVersion = JavaLanguageVersion.of(21)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
|
implementation("org.springframework.boot:spring-boot-starter")
|
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
|
}
|
|
|
|
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(file: File) {
|
|
val md5 = generateHash(file, "MD5")
|
|
val sha1 = generateHash(file, "SHA-1")
|
|
val sha256 = generateHash(file, "SHA-256")
|
|
val md5f = File(libDir, file.getName() + ".MD5.txt")
|
|
val sha1f = File(libDir, file.getName() + ".SHA1.txt")
|
|
val sha256f = File(libDir, file.getName() + ".SHA256.txt")
|
|
md5f.writeText(md5)
|
|
sha1f.writeText(sha1)
|
|
sha256f.writeText(sha256)
|
|
}
|
|
|
|
tasks.withType<Test> {
|
|
useJUnitPlatform()
|
|
}
|
|
tasks.register<Zip>("sources") {
|
|
archiveFileName.set(srcJarName)
|
|
destinationDirectory.set(libDir)
|
|
from(fileTree(srcDir.toString()))
|
|
into(".")
|
|
}
|
|
tasks.register<Zip>("web") {
|
|
archiveFileName.set(webZipName)
|
|
destinationDirectory.set(libDir)
|
|
from(fileTree(webDir.toString()))
|
|
into(".")
|
|
}
|
|
tasks.bootJar {
|
|
archiveFileName.set(jarName)
|
|
doFirst {
|
|
delete(libDir)
|
|
mkdir(libDir)
|
|
}
|
|
manifest {
|
|
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
|
|
}
|
|
}
|
|
|
|
tasks.register("build-jar") {
|
|
dependsOn(tasks["sources"])
|
|
dependsOn(tasks["web"])
|
|
dependsOn(tasks.bootJar)
|
|
doLast {
|
|
getHash(File(libDir, jarName))
|
|
getHash(File(libDir, srcJarName))
|
|
getHash(File(libDir, webZipName))
|
|
}
|
|
}
|