Coeur-Morny-Cono/build.gradle
Eyre_S 201c8bcd1a
添加项目 git 链接相关配置,大改动版本显示方式,/version 与 /runtime 合并进 /info
- 将 /version 和 /runtime 合并为了 /info 的子命令
  - 旧的 /version 和 /runtime 命令仍然可用
  - runtime 现在是 /info 的无参数行为
- 更新了各种位置的版本显示方式
  - /version 现在通过组装的方式显示版本号的 BASE 与 DELTA 部分,并支持了可能的 git commit 显示,同时支持输出 commit 链接
  - /runtime 现在通过组装的方式显示版本号的 BASE, DELTA, GIT 部分,其中也支持了 git commit 链接,同时 CODENAME 的显示方式规范为了 `version*CODENAME` 的格式
  - ServerMain 的 -v 修改了显示格式,同时添加了 gitstat 字段显示 build 时的 git 信息
  - ServerMain 的启动版本回显(仍使用完全体VERSION)将 md5hash 和 code-time 移到了新行
- dependencies update
  - java-telegram-bot-api: 5.6.0 -> 6.2.0
2022-11-09 01:41:01 +08:00

185 lines
5.2 KiB
Groovy

import org.ajoberstar.grgit.Status
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
plugins {
id 'java'
id 'java-library'
id 'application'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.github.gmazzo.buildconfig' version '3.1.0'
id 'org.ajoberstar.grgit' version '5.0.0'
}
final boolean proj_git = grgit!=null
final String proj_store = MORNY_CODE_STORE
final String proj_commit = proj_git ? grgit.head().id : null
final String proj_commit_path = MORNY_COMMIT_PATH
final boolean proj_clean = isCleanBuild()
if (!proj_git)
print "[MornyBuild] git repository not available for current working space! git version tag will be disabled."
else if (isCleanBuild()) {
print "git: clean build at ${grgit.head().id}"
} else {
final Status status = grgit.status()
print "git: non-clean-build"
if (!status.unstaged.allChanges.empty) {
print "\ngit: unstaged changes"
listChanges(status.unstaged)
}
if (!status.staged.allChanges.empty) {
print "\ngit: staged changes"
listChanges(status.staged)
}
}
final String proj_group = 'cc.sukazyo'
final String proj_package = "${proj_group}.cono.morny"
final String proj_archive_name = MORNY_ARCHIVE_NAME
final String proj_application_main = "${proj_package}.ServerMain"
final String proj_version_base = VERSION
final String proj_version_delta = VERSION_DELTA
final boolean proj_version_use_delta = Boolean.parseBoolean(USE_DELTA)
String proj_version = proj_version_base
if (proj_version_use_delta) proj_version += "-δ${proj_version_delta}"
if (proj_git) proj_version += "+git.${proj_commit.substring(0, 8)}" + (proj_clean?"":".δ")
final String proj_version_codename = CODENAME
final long proj_code_time = proj_clean ? grgit.head().dateTime.toInstant().toEpochMilli() : System.currentTimeMillis()
final JavaVersion proj_java = JavaVersion.VERSION_17
final Charset proj_file_encoding = StandardCharsets.UTF_8
String publish_local_url = null
String publish_remote_url = null
String publish_remote_username = null
String publish_remote_password = null
if (project.hasProperty("publishLocalArchiveRepoUrl")) publish_local_url = publishLocalArchiveRepoUrl
if (project.hasProperty("publishMvnRepoUrl")) {
publish_remote_url = publishMvnRepoUrl
publish_remote_username = publishMvnRepoUsername
publish_remote_password = publishMvnRepoPassword
}
group proj_group
version proj_version
setArchivesBaseName proj_archive_name
repositories {
mavenCentral()
maven { name '-ws'; url 'https://mvn.sukazyo.cc/releases' }
}
dependencies {
compileOnlyApi "com.github.spotbugs:spotbugs-annotations:${libSpotbugsVersion}"
api "cc.sukazyo:messiva:${libMessivaVersion}"
implementation "com.github.pengrad:java-telegram-bot-api:${libJavaTelegramBotApiVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${libJunitVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-params:${libJunitVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${libJunitVersion}"
}
application {
mainClass = proj_application_main
}
test {
useJUnitPlatform()
}
java {
sourceCompatibility proj_java
targetCompatibility proj_java
withSourcesJar()
}
tasks.withType(JavaCompile) {
options.encoding = proj_file_encoding.name()
}
tasks.withType(Javadoc) {
options.encoding = proj_file_encoding.name()
options.docEncoding = proj_file_encoding.name()
options.charSet = proj_file_encoding.name()
}
tasks.test {
useJUnitPlatform()
}
buildConfig {
packageName(proj_package)
buildConfigField('String', 'VERSION', "\"${proj_version}\"")
buildConfigField('String', 'VERSION_BASE', "\"${proj_version_base}\"")
buildConfigField('String', 'VERSION_DELTA', proj_version_use_delta ? "\"${proj_version_delta}\"" : "null")
buildConfigField('String', 'CODENAME', "\"${proj_version_codename}\"")
buildConfigField('long', 'CODE_TIMESTAMP', "${proj_code_time}L")
buildConfigField('String', 'COMMIT', proj_git ? "\"${proj_commit}\"" : "null")
buildConfigField('boolean', 'CLEAN_BUILD', "${proj_clean}")
buildConfigField('String', 'CODE_STORE', proj_store==""?"null":"\"${proj_store}\"")
buildConfigField('String', 'COMMIT_PATH', proj_commit_path==""?"null":"\"${proj_commit_path}\"")
}
shadowJar {
archiveClassifier.set "fat"
}
@SuppressWarnings("all")
boolean isCleanBuild () {
if (grgit == null) return false
Set<String> changes = grgit.status().unstaged.allChanges + grgit.status().staged.allChanges
for (String file in changes) {
if (file.startsWith("src/")) return false
if (file == "build.gradle") return false
if (file == "gradle.properties") return false
}
return true
}
void listChanges (Status.Changes listing) {
for (String file in listing.added)
print "\n add: ${file}"
for (String file in listing.modified)
print "\n mod: ${file}"
for (String file in listing.removed)
print "\n del: ${file}"
}
publishing {
repositories{
if (publish_local_url != null) maven {
name 'archives'
url publish_local_url
}
if (publish_remote_url != null) maven {
name '-ws-'
url publish_remote_url
credentials {
username publish_remote_username
password publish_remote_password
}
}
}
publications {
main (MavenPublication) {
from components.java
groupId = proj_group
artifactId = proj_archive_name
version = proj_version
}
}
}