Coeur-Morny-Cono/build.gradle

168 lines
4.5 KiB
Groovy
Raw Normal View History

import org.ajoberstar.grgit.Status
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
2021-10-07 20:50:59 +08:00
plugins {
id 'java'
id 'java-library'
id 'maven-publish'
id 'application'
id 'com.github.johnrengelman.shadow' version '7.1.0'
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_commit = proj_git ? grgit.head().id : null
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()
println "git: non-clean-build"
if (!status.unstaged.allChanges.empty) {
println "git: unstaged changes"
listChanges(status.unstaged)
}
if (!status.staged.allChanges.empty) {
println "[MornyBuild] git: staged changes"
listChanges(status.staged)
}
2021-10-07 20:50:59 +08:00
}
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_version_base = VERSION
final String proj_version_delta = VERSION_DELTA
final String proj_version_use_delta = Boolean.parseBoolean(VERSION_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
group proj_group
version proj_version
project.ext.archiveBaseName = proj_archive_name
project.ext.artifactId = proj_archive_name
mainClassName = "${proj_package}.ServerMain"
2021-10-07 20:50:59 +08:00
repositories {
mavenCentral()
maven { name '-ws'; url 'https://mvn.sukazyo.cc/releases' }
2021-10-07 20:50:59 +08:00
}
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}"
2021-10-07 20:50:59 +08:00
}
test {
useJUnitPlatform()
}
2021-11-09 17:33:56 +08:00
java {
sourceCompatibility proj_java
targetCompatibility proj_java
withSourcesJar()
}
2021-11-09 17:33:56 +08:00
tasks.withType(JavaCompile) {
options.encoding = proj_file_encoding.name()
2021-11-09 17:33:56 +08:00
}
tasks.withType(Javadoc) {
options.encoding = proj_file_encoding.name()
options.docEncoding = proj_file_encoding.name()
options.charSet = proj_file_encoding.name()
2021-11-09 17:33:56 +08:00
}
tasks.test {
useJUnitPlatform()
}
buildConfig {
packageName(proj_package)
buildConfigField('String', 'VERSION', "\"${proj_version}\"")
buildConfigField('String', 'VERSION_DELTA', "\"${proj_version_delta}\"")
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}")
}
shadowJar {
archiveBaseName.set("${project.ext.archiveBaseName}")
archiveVersion.set("${project.version}")
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)
println " add: ${file}"
for (String file in listing.modified)
println " mod: ${file}"
for (String file in listing.removed)
println " del: ${file}"
}
publishing {
repositories{
maven {
name 'builds'
url publishLocalArchiveRepoUrl
}
maven {
name '-ws-'
url publishMvnRepoUrl
credentials {
username publishMvnRepoUsername
password publishMvnRepoPassword
}
}
}
publications {
main (MavenPublication) {
from components.java
groupId = project.group
artifactId = project.ext.artifactId
version = project.version
}
}
2021-11-09 17:33:56 +08:00
}