mirai/build.gradle.kts

147 lines
4.9 KiB
Plaintext
Raw Normal View History

2020-03-25 13:48:27 +08:00
@file:Suppress("UnstableApiUsage", "UNUSED_VARIABLE")
2020-03-25 12:18:58 +08:00
import java.time.Duration
2020-03-01 13:00:34 +08:00
import java.util.*
2020-03-25 10:12:24 +08:00
import kotlin.math.pow
2020-03-01 13:00:34 +08:00
buildscript {
repositories {
mavenLocal()
2020-03-07 22:23:10 +08:00
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
2020-03-24 10:01:03 +08:00
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
2020-03-01 13:00:34 +08:00
jcenter()
google()
}
dependencies {
2020-03-25 10:12:24 +08:00
classpath("com.github.jengelman.gradle.plugins:shadow:5.2.0")
2020-03-24 10:01:03 +08:00
classpath("com.android.tools.build:gradle:${Versions.Android.androidGradlePlugin}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Kotlin.stdlib}")
classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.Kotlin.stdlib}")
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.Kotlin.atomicFU}")
2020-03-01 13:00:34 +08:00
}
}
2020-03-23 19:31:22 +08:00
plugins {
2020-03-24 10:01:03 +08:00
id("org.jetbrains.dokka") version Versions.Kotlin.dokka apply false
2020-03-25 10:12:24 +08:00
// id("com.jfrog.bintray") version Versions.Publishing.bintray apply false
2020-03-23 19:31:22 +08:00
}
2020-03-01 13:00:34 +08:00
runCatching {
val keyProps = Properties().apply {
file("local.properties").takeIf { it.exists() }?.inputStream()?.use { load(it) }
}
if (keyProps.getProperty("sdk.dir", "").isNotEmpty()) {
project.ext.set("isAndroidSDKAvailable", true)
} else {
project.ext.set("isAndroidSDKAvailable", false)
}
}
allprojects {
group = "net.mamoe"
2020-03-24 17:32:22 +08:00
version = Versions.Mirai.version
2020-03-01 13:00:34 +08:00
repositories {
2020-03-07 22:23:10 +08:00
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
2020-03-24 10:01:03 +08:00
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
2020-03-01 13:00:34 +08:00
jcenter()
google()
}
2020-03-25 10:12:24 +08:00
}
subprojects {
afterEvaluate {
apply(plugin = "com.github.johnrengelman.shadow")
val kotlin =
(this as ExtensionAware).extensions.getByName("kotlin") as? org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
?: return@afterEvaluate
val shadowJvmJar by tasks.creating(com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar::class) {
group = "mirai"
2020-03-29 19:28:44 +08:00
val compilations =
kotlin.targets.filter { it.platformType == org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.jvm }
.map { it.compilations["main"] }
2020-03-25 10:12:24 +08:00
2020-03-29 19:28:44 +08:00
compilations.forEach {
dependsOn(it.compileKotlinTask)
}
2020-03-25 10:12:24 +08:00
2020-03-29 19:28:44 +08:00
compilations.forEach {
from(it.output)
}
configurations = compilations.map { it.compileDependencyFiles as Configuration }
2020-03-26 21:17:30 +08:00
this.exclude { file ->
file.name.endsWith(".sf", ignoreCase = true)
.also { if (it) println("excluded ${file.name}") }
}
2020-03-25 10:12:24 +08:00
}
2020-03-25 13:48:27 +08:00
val githubUpload by tasks.creating {
2020-03-25 10:12:24 +08:00
group = "mirai"
dependsOn(shadowJvmJar)
doFirst {
timeout.set(Duration.ofHours(3))
findLatestFile()?.let { (_, file) ->
val filename = file.name
println("Uploading file $filename")
runCatching {
upload.GitHub.upload(
file,
"https://api.github.com/repos/mamoe/mirai-repo/contents/shadow/${project.name}/$filename",
project
)
}.exceptionOrNull()?.let {
System.err.println("GitHub Upload failed")
it.printStackTrace() // force show stacktrace
throw it
2020-03-25 10:12:24 +08:00
}
}
}
}
val cuiCloudUpload by tasks.creating {
group = "mirai"
dependsOn(shadowJvmJar)
doFirst {
timeout.set(Duration.ofHours(3))
findLatestFile()?.let { (_, file) ->
val filename = file.name
println("Uploading file $filename")
runCatching {
upload.CuiCloud.upload(
file,
project
)
}.exceptionOrNull()?.let {
System.err.println("CuiCloud Upload failed")
it.printStackTrace() // force show stacktrace
throw it
}
}
2020-03-25 10:12:24 +08:00
}
}
}
}
fun Project.findLatestFile(): Map.Entry<String, File>? {
return File(projectDir, "build/libs").walk()
.filter { it.isFile }
.onEach { println("all files=$it") }
.filter { it.name.matches(Regex("""${project.name}-([0-9]|\.)*\.jar""")) }
.onEach { println("matched file: ${it.name}") }
.associateBy { it.nameWithoutExtension.substringAfterLast('-') }
.onEach { println("versions: $it") }
.maxBy {
it.key.split('.').foldRightIndexed(0) { index: Int, s: String, acc: Int ->
acc + 100.0.pow(2 - index).toInt() * (s.toIntOrNull() ?: 0)
}
}
2020-03-01 13:00:34 +08:00
}