2021-10-07 20:50:59 +08:00
|
|
|
plugins {
|
2023-09-05 14:14:01 +08:00
|
|
|
id 'scala'
|
2021-11-27 21:07:40 +08:00
|
|
|
id 'java-library'
|
2021-11-26 14:09:40 +08:00
|
|
|
id 'application'
|
2022-11-07 12:54:01 +08:00
|
|
|
id 'maven-publish'
|
2023-09-16 23:12:44 +08:00
|
|
|
id "io.github.ysohda.scalatest" version "0.32.1"
|
2023-08-15 14:10:13 +08:00
|
|
|
id 'com.github.johnrengelman.shadow' version '8.1.1'
|
2023-08-20 23:11:10 +08:00
|
|
|
id 'com.github.gmazzo.buildconfig' version '4.1.2'
|
2023-08-15 14:10:13 +08:00
|
|
|
id 'org.ajoberstar.grgit' version '5.2.0'
|
2022-11-06 21:31:24 +08:00
|
|
|
}
|
|
|
|
|
2023-08-15 14:10:13 +08:00
|
|
|
import org.ajoberstar.grgit.Status
|
|
|
|
|
|
|
|
import java.nio.charset.Charset
|
|
|
|
import java.nio.charset.StandardCharsets
|
|
|
|
|
2023-10-18 23:40:17 +08:00
|
|
|
final boolean proj_git = grgit != null
|
2022-11-09 01:41:01 +08:00
|
|
|
final String proj_store = MORNY_CODE_STORE
|
2022-11-06 21:31:24 +08:00
|
|
|
final String proj_commit = proj_git ? grgit.head().id : null
|
2022-11-09 01:41:01 +08:00
|
|
|
final String proj_commit_path = MORNY_COMMIT_PATH
|
2022-11-06 21:31:24 +08:00
|
|
|
final boolean proj_clean = isCleanBuild()
|
|
|
|
if (!proj_git)
|
2023-08-15 14:10:13 +08:00
|
|
|
println "[MornyBuild] git repository not available for current working space! git version tag will be disabled."
|
2022-11-06 21:31:24 +08:00
|
|
|
else if (isCleanBuild()) {
|
2023-08-15 14:10:13 +08:00
|
|
|
println "git: clean build at ${grgit.head().id}"
|
2023-10-18 23:40:17 +08:00
|
|
|
}
|
|
|
|
else {
|
2022-11-06 21:31:24 +08:00
|
|
|
final Status status = grgit.status()
|
2023-08-15 14:10:13 +08:00
|
|
|
println "git: non-clean-build"
|
2022-11-06 21:31:24 +08:00
|
|
|
if (!status.unstaged.allChanges.empty) {
|
2023-08-15 14:10:13 +08:00
|
|
|
println "git: unstaged changes"
|
2022-11-06 21:31:24 +08:00
|
|
|
listChanges(status.unstaged)
|
|
|
|
}
|
|
|
|
if (!status.staged.allChanges.empty) {
|
2023-08-15 14:10:13 +08:00
|
|
|
println "git: staged changes"
|
2022-11-06 21:31:24 +08:00
|
|
|
listChanges(status.staged)
|
|
|
|
}
|
2021-10-07 20:50:59 +08:00
|
|
|
}
|
|
|
|
|
2022-11-06 20:07:11 +08:00
|
|
|
final String proj_group = 'cc.sukazyo'
|
|
|
|
final String proj_package = "${proj_group}.cono.morny"
|
|
|
|
final String proj_archive_name = MORNY_ARCHIVE_NAME
|
2022-11-07 12:54:01 +08:00
|
|
|
final String proj_application_main = "${proj_package}.ServerMain"
|
2022-11-06 20:07:11 +08:00
|
|
|
|
|
|
|
final String proj_version_base = VERSION
|
|
|
|
final String proj_version_delta = VERSION_DELTA
|
2022-11-08 22:37:46 +08:00
|
|
|
final boolean proj_version_use_delta = Boolean.parseBoolean(USE_DELTA)
|
2022-11-09 12:03:17 +08:00
|
|
|
final String proj_version = proj_version_base + (proj_version_use_delta ? "-δ${proj_version_delta}" : "")
|
2023-10-18 23:40:17 +08:00
|
|
|
final String proj_version_full = proj_version + (proj_git ?
|
|
|
|
"+git.${proj_commit.substring(0, 8)}" + (proj_clean ? "" : ".δ") : "")
|
2022-11-06 20:07:11 +08:00
|
|
|
final String proj_version_codename = CODENAME
|
2022-11-06 21:43:15 +08:00
|
|
|
final long proj_code_time = proj_clean ? grgit.head().dateTime.toInstant().toEpochMilli() : System.currentTimeMillis()
|
2022-11-06 20:07:11 +08:00
|
|
|
|
|
|
|
final JavaVersion proj_java = JavaVersion.VERSION_17
|
|
|
|
final Charset proj_file_encoding = StandardCharsets.UTF_8
|
2023-09-05 14:14:01 +08:00
|
|
|
final proj_scala_api = 3
|
|
|
|
//final proj_scala_lib = proj_scala_api+'.4.0-RC1-bin-20230901-89e8dba-NIGHTLY'
|
2023-10-18 23:40:17 +08:00
|
|
|
final proj_scala_lib = proj_scala_api + '.3.1'
|
2022-11-07 12:54:01 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-11-06 20:07:11 +08:00
|
|
|
group proj_group
|
2022-11-09 12:03:17 +08:00
|
|
|
version proj_version_full
|
2021-10-07 20:50:59 +08:00
|
|
|
|
|
|
|
repositories {
|
|
|
|
mavenCentral()
|
2022-09-19 23:54:02 +08:00
|
|
|
maven { name '-ws'; url 'https://mvn.sukazyo.cc/releases' }
|
2021-10-07 20:50:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dependencies {
|
2021-11-06 20:43:56 +08:00
|
|
|
|
2023-10-19 21:43:29 +08:00
|
|
|
api group: 'org.scala-lang', name: 'scala3-library_3', version: proj_scala_lib
|
|
|
|
final scala = (String name) -> "${name}_$proj_scala_api"
|
|
|
|
compileOnlyApi group: 'com.github.spotbugs', name: 'spotbugs-annotations', version: lib_spotbugs_v
|
2021-11-27 21:07:40 +08:00
|
|
|
|
2023-10-19 21:43:29 +08:00
|
|
|
implementation group: 'cc.sukazyo', name: 'messiva', version: lib_messiva_v
|
|
|
|
implementation group: 'cc.sukazyo', name: 'resource-tools', version: lib_resourcetools_v
|
2021-12-11 00:10:22 +08:00
|
|
|
|
2023-10-19 21:43:29 +08:00
|
|
|
implementation group: 'com.github.pengrad', name: 'java-telegram-bot-api', version: lib_javatelegramapi_v
|
|
|
|
implementation group: 'com.softwaremill.sttp.client3', name: scala('core'), version: lib_sttp_v
|
|
|
|
implementation group: 'com.softwaremill.sttp.client3', name: scala('okhttp-backend'), version: lib_sttp_v
|
2023-11-14 13:56:23 +08:00
|
|
|
runtimeOnly group: 'com.squareup.okhttp3', name: 'okhttp', version: lib_okhttp_v
|
2023-10-19 21:43:29 +08:00
|
|
|
implementation group: 'com.google.code.gson', name: 'gson', version: lib_gson_v
|
2023-11-09 22:07:10 +08:00
|
|
|
implementation group: 'com.cronutils', name: 'cron-utils', version: lib_cron_utils_v
|
2023-10-19 21:43:29 +08:00
|
|
|
|
2023-11-14 13:56:23 +08:00
|
|
|
// used for disable slf4j
|
|
|
|
// due to the slf4j api have been used in the following libraries:
|
|
|
|
// - cron-utils
|
|
|
|
runtimeOnly group: 'org.slf4j', name: 'slf4j-nop', version: lib_slf4j_v
|
|
|
|
testRuntimeOnly group: 'org.slf4j', name: 'slf4j-nop', version: lib_slf4j_v
|
|
|
|
|
|
|
|
testImplementation group: 'cc.sukazyo', name: 'resource-tools', version: lib_resourcetools_v
|
2023-10-19 21:43:29 +08:00
|
|
|
testImplementation group: 'org.scalatest', name: scala('scalatest'), version: lib_scalatest_v
|
|
|
|
testImplementation group: 'org.scalatest', name: scala('scalatest-freespec'), version: lib_scalatest_v
|
|
|
|
testRuntimeOnly group: 'org.scala-lang.modules', name: scala('scala-xml'), version: lib_scalamodule_xml_v
|
2023-11-14 13:56:23 +08:00
|
|
|
// for generating HTML report: required by gradle-scalatest plugin
|
2023-10-19 21:43:29 +08:00
|
|
|
testRuntimeOnly group: 'com.vladsch.flexmark', name: 'flexmark-all', version: '0.64.6'
|
2021-11-06 20:43:56 +08:00
|
|
|
|
2021-10-07 20:50:59 +08:00
|
|
|
}
|
|
|
|
|
2023-10-06 22:24:14 +08:00
|
|
|
java {
|
|
|
|
withSourcesJar()
|
|
|
|
}
|
|
|
|
|
2023-10-12 14:39:18 +08:00
|
|
|
sourceSets {
|
|
|
|
|
|
|
|
main {
|
|
|
|
java { destinationDirectory.set file("build/classes/main") }
|
|
|
|
scala { destinationDirectory.set file("build/classes/main") }
|
|
|
|
}
|
|
|
|
|
|
|
|
test {
|
|
|
|
java { destinationDirectory.set file("build/classes/test") }
|
|
|
|
scala { destinationDirectory.set file("build/classes/test") }
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-09-10 22:43:39 +08:00
|
|
|
tasks.withType(JavaCompile).configureEach {
|
|
|
|
|
|
|
|
sourceCompatibility proj_java.getMajorVersion()
|
|
|
|
targetCompatibility proj_java.getMajorVersion()
|
|
|
|
|
|
|
|
options.encoding = proj_file_encoding.name()
|
|
|
|
|
2021-10-07 20:50:59 +08:00
|
|
|
}
|
2021-11-09 17:33:56 +08:00
|
|
|
|
2023-09-10 22:43:39 +08:00
|
|
|
tasks.withType(ScalaCompile).configureEach {
|
2021-12-05 20:15:51 +08:00
|
|
|
|
2023-09-10 22:43:39 +08:00
|
|
|
sourceCompatibility proj_java.getMajorVersion()
|
|
|
|
targetCompatibility proj_java.getMajorVersion()
|
2021-12-05 20:15:51 +08:00
|
|
|
|
2023-09-10 22:43:39 +08:00
|
|
|
scalaCompileOptions.additionalParameters.add "-language:postfixOps"
|
2023-09-16 23:12:44 +08:00
|
|
|
|
2023-10-12 14:39:18 +08:00
|
|
|
scalaCompileOptions.encoding = proj_file_encoding.name()
|
|
|
|
options.encoding = proj_file_encoding.name()
|
|
|
|
|
2023-09-16 23:12:44 +08:00
|
|
|
}
|
2023-09-10 22:43:39 +08:00
|
|
|
|
2023-09-16 23:12:44 +08:00
|
|
|
tasks.withType(Javadoc).configureEach {
|
|
|
|
options.encoding = proj_file_encoding.name()
|
2021-11-26 14:09:40 +08:00
|
|
|
}
|
|
|
|
|
2023-09-16 23:12:44 +08:00
|
|
|
//tasks.withType(ScalaDoc).configureEach {
|
|
|
|
//}
|
|
|
|
|
2023-09-05 14:14:01 +08:00
|
|
|
test {
|
2021-11-09 17:33:56 +08:00
|
|
|
}
|
|
|
|
|
2023-09-05 14:14:01 +08:00
|
|
|
application {
|
|
|
|
mainClass = proj_application_main
|
2021-11-09 17:33:56 +08:00
|
|
|
}
|
|
|
|
|
2022-11-06 20:07:11 +08:00
|
|
|
buildConfig {
|
|
|
|
|
|
|
|
packageName(proj_package)
|
|
|
|
|
2022-11-06 21:31:24 +08:00
|
|
|
buildConfigField('String', 'VERSION', "\"${proj_version}\"")
|
2022-11-09 12:03:17 +08:00
|
|
|
buildConfigField('String', 'VERSION_FULL', "\"${proj_version_full}\"")
|
2022-11-09 01:41:01 +08:00
|
|
|
buildConfigField('String', 'VERSION_BASE', "\"${proj_version_base}\"")
|
2022-11-08 22:37:46 +08:00
|
|
|
buildConfigField('String', 'VERSION_DELTA', proj_version_use_delta ? "\"${proj_version_delta}\"" : "null")
|
2022-11-06 21:31:24 +08:00
|
|
|
buildConfigField('String', 'CODENAME', "\"${proj_version_codename}\"")
|
2022-11-06 21:43:15 +08:00
|
|
|
buildConfigField('long', 'CODE_TIMESTAMP', "${proj_code_time}L")
|
2023-10-18 23:40:17 +08:00
|
|
|
buildConfigField('String', 'COMMIT', proj_git ? "\"${proj_commit}\"" : "null")
|
2022-11-06 21:31:24 +08:00
|
|
|
buildConfigField('boolean', 'CLEAN_BUILD', "${proj_clean}")
|
2023-10-18 23:40:17 +08:00
|
|
|
buildConfigField('String', 'CODE_STORE', proj_store == "" ? "null" : "\"${proj_store}\"")
|
|
|
|
buildConfigField('String', 'COMMIT_PATH', proj_commit_path == "" ? "null" : "\"${proj_commit_path}\"")
|
2022-11-06 20:07:11 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-10-06 22:24:14 +08:00
|
|
|
tasks.withType(Jar).configureEach {
|
|
|
|
archiveBaseName.set proj_archive_name
|
|
|
|
}
|
|
|
|
|
2021-11-26 14:09:40 +08:00
|
|
|
shadowJar {
|
2023-08-15 14:10:13 +08:00
|
|
|
|
2022-11-07 12:54:01 +08:00
|
|
|
archiveClassifier.set "fat"
|
2023-08-15 14:10:13 +08:00
|
|
|
|
|
|
|
if (project.hasProperty("dockerBuild")) {
|
|
|
|
println "shadow-jar: using docker build name"
|
|
|
|
archiveVersion.set ""
|
|
|
|
archiveClassifier.set "docker-build"
|
|
|
|
}
|
|
|
|
|
2021-11-26 14:09:40 +08:00
|
|
|
}
|
|
|
|
|
2023-09-16 23:12:44 +08:00
|
|
|
@SuppressWarnings('GrMethodMayBeStatic')
|
2022-11-06 21:31:24 +08:00
|
|
|
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)
|
2023-08-15 14:10:13 +08:00
|
|
|
println " add: ${file}"
|
2022-11-06 21:31:24 +08:00
|
|
|
for (String file in listing.modified)
|
2023-08-15 14:10:13 +08:00
|
|
|
println " mod: ${file}"
|
2022-11-06 21:31:24 +08:00
|
|
|
for (String file in listing.removed)
|
2023-08-15 14:10:13 +08:00
|
|
|
println " del: ${file}"
|
2022-11-06 21:31:24 +08:00
|
|
|
}
|
|
|
|
|
2021-11-26 14:09:40 +08:00
|
|
|
publishing {
|
2023-10-18 23:40:17 +08:00
|
|
|
repositories {
|
2022-11-07 12:54:01 +08:00
|
|
|
if (publish_local_url != null) maven {
|
|
|
|
name 'archives'
|
|
|
|
url publish_local_url
|
2021-11-26 14:09:40 +08:00
|
|
|
}
|
2022-11-07 12:54:01 +08:00
|
|
|
if (publish_remote_url != null) maven {
|
2021-11-26 14:09:40 +08:00
|
|
|
name '-ws-'
|
2022-11-07 12:54:01 +08:00
|
|
|
url publish_remote_url
|
2021-11-26 14:09:40 +08:00
|
|
|
credentials {
|
2022-11-07 12:54:01 +08:00
|
|
|
username publish_remote_username
|
|
|
|
password publish_remote_password
|
2021-11-26 14:09:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
publications {
|
2023-09-23 16:38:07 +08:00
|
|
|
//noinspection GroovyAssignabilityCheck
|
2023-10-18 23:40:17 +08:00
|
|
|
main(MavenPublication) {
|
2023-09-23 16:38:07 +08:00
|
|
|
//noinspection GroovyAssignabilityCheck
|
2021-11-26 14:09:40 +08:00
|
|
|
from components.java
|
2023-09-23 16:38:07 +08:00
|
|
|
//noinspection GroovyAssignabilityCheck
|
2022-11-07 12:54:01 +08:00
|
|
|
groupId = proj_group
|
2023-09-23 16:38:07 +08:00
|
|
|
//noinspection GroovyAssignabilityCheck
|
2022-11-07 12:54:01 +08:00
|
|
|
artifactId = proj_archive_name
|
2023-09-23 16:38:07 +08:00
|
|
|
//noinspection GroovyAssignabilityCheck
|
2022-11-07 12:54:01 +08:00
|
|
|
version = proj_version
|
2021-11-26 14:09:40 +08:00
|
|
|
}
|
|
|
|
}
|
2021-11-09 17:33:56 +08:00
|
|
|
}
|