mirai/build.gradle.kts

294 lines
11 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 org.jetbrains.dokka.gradle.DokkaTask
2020-03-25 12:18:58 +08:00
import java.time.Duration
2020-03-25 10:12:24 +08:00
import kotlin.math.pow
2020-03-01 13:00:34 +08:00
buildscript {
repositories {
mavenLocal()
2020-05-04 15:10:31 +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")
maven(url = "https://kotlin.bintray.com/kotlinx")
2020-03-01 13:00:34 +08:00
jcenter()
google()
mavenCentral()
2020-03-01 13:00:34 +08:00
}
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}")
2020-07-20 15:06:30 +08:00
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Kotlin.compiler}")
classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.Kotlin.compiler}")
2020-03-24 10:01:03 +08:00
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.Kotlin.atomicFU}")
2020-05-09 15:37:02 +08:00
classpath("org.jetbrains.kotlinx:binary-compatibility-validator:${Versions.Kotlin.binaryValidator}")
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-05-09 15:37:02 +08:00
// https://github.com/kotlin/binary-compatibility-validator
2020-05-10 01:11:57 +08:00
//apply(plugin = "binary-compatibility-validator")
2020-05-09 15:37:02 +08:00
2020-04-10 16:13:03 +08:00
project.ext.set("isAndroidSDKAvailable", false)
// until
// https://youtrack.jetbrains.com/issue/KT-37152,
// are fixed.
/*
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)
}
2020-04-08 10:39:13 +08:00
}.exceptionOrNull()?.run {
project.ext.set("isAndroidSDKAvailable", false)
2020-04-10 16:13:03 +08:00
}*/
2020-03-01 13:00:34 +08:00
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-05-23 15:25:37 +08:00
mavenLocal()
2020-05-04 15:10:31 +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")
maven(url = "https://kotlin.bintray.com/kotlinx")
2020-03-01 13:00:34 +08:00
jcenter()
google()
mavenCentral()
2020-03-01 13:00:34 +08:00
}
2020-03-25 10:12:24 +08:00
}
subprojects {
if (this@subprojects.name == "java-test") {
return@subprojects
}
2020-03-25 10:12:24 +08:00
afterEvaluate {
apply(plugin = "com.github.johnrengelman.shadow")
val kotlin =
runCatching {
(this as ExtensionAware).extensions.getByName("kotlin") as? org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
}.getOrNull() ?: return@afterEvaluate
2020-03-25 10:12:24 +08:00
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}") }
}
this.manifest {
this.attributes(
"Manifest-Version" to 1,
"Implementation-Vendor" to "Mamoe Technologies",
"Implementation-Title" to this@afterEvaluate.name.toString(),
"Implementation-Version" to this@afterEvaluate.version.toString()
)
}
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))
2020-05-24 16:42:42 +08:00
findLatestFile().let { (_, file) ->
val filename = file.name
println("Uploading file $filename")
runCatching {
upload.GitHub.upload(
file,
2020-05-24 16:42:42 +08:00
project,
"mirai-repo",
"shadow/${project.name}/$filename"
)
}.exceptionOrNull()?.let {
System.err.println("GitHub Upload failed")
it.printStackTrace() // force show stacktrace
throw it
2020-03-25 10:12:24 +08:00
}
}
}
}
2020-05-24 16:42:42 +08:00
apply(plugin = "org.jetbrains.dokka")
this.tasks {
val dokka by getting(DokkaTask::class) {
2020-05-24 16:42:42 +08:00
outputFormat = "html"
outputDirectory = "$buildDir/dokka"
}
val dokkaMarkdown by creating(DokkaTask::class) {
2020-05-24 16:42:42 +08:00
outputFormat = "markdown"
outputDirectory = "$buildDir/dokka-markdown"
}
val dokkaGfm by creating(DokkaTask::class) {
2020-05-24 16:42:42 +08:00
outputFormat = "gfm"
outputDirectory = "$buildDir/dokka-gfm"
}
}
val dokkaGitHubUpload by tasks.creating {
group = "mirai"
val dokkaTaskName = "dokka"
dependsOn(tasks.getByName(dokkaTaskName))
2020-05-24 16:42:42 +08:00
doFirst {
val baseDir = file("./build/$dokkaTaskName/${project.name}")
2020-05-24 16:42:42 +08:00
timeout.set(Duration.ofHours(6))
file("build/$dokkaTaskName/").walk()
2020-05-24 16:42:42 +08:00
.filter { it.isFile }
.map { old ->
if (old.name == "index.md") File(old.parentFile, "README.md").also { new -> old.renameTo(new) }
else old
}
// optimize md
2020-05-24 16:42:42 +08:00
.forEach { file ->
if (file.endsWith(".md")) {
file.writeText(
file.readText().replace("index.md", "README.md", ignoreCase = true)
.replace(Regex("""```\n([\s\S]*?)```""")) {
"\n" + """
```kotlin
$it
```
""".trimIndent()
})
} /* else if (file.name == "README.md") {
file.writeText(file.readText().replace(Regex("""(\n\n\|\s)""")) {
"\n\n" + """"
|||
|:----------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
""".trimIndent()
})
}*/
2020-05-24 16:42:42 +08:00
val filename = file.toRelativeString(baseDir)
println("Uploading file $filename")
runCatching {
upload.GitHub.upload(
file,
project,
"mirai-doc",
"${project.name}/${project.version}/$filename"
2020-05-24 16:42:42 +08:00
)
}.exceptionOrNull()?.let {
System.err.println("GitHub Upload failed")
it.printStackTrace() // force show stacktrace
throw it
}
}
}
}
val cuiCloudUpload by tasks.creating {
group = "mirai"
dependsOn(shadowJvmJar)
doFirst {
timeout.set(Duration.ofHours(3))
2020-05-24 16:42:42 +08:00
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
}
}
}
2020-05-24 16:42:42 +08:00
afterEvaluate {
tasks.filterIsInstance<DokkaTask>().forEach { task ->
2020-05-24 16:42:42 +08:00
with(task) {
configuration {
perPackageOption {
prefix = "net.mamoe.mirai"
skipDeprecated = true
}
perPackageOption {
prefix = "net.mamoe.mirai.internal"
suppress = true
}
perPackageOption {
prefix = "net.mamoe.mirai.event.internal"
suppress = true
}
perPackageOption {
prefix = "net.mamoe.mirai.utils.internal"
suppress = true
}
perPackageOption {
prefix = "net.mamoe.mirai.qqandroid.utils"
suppress = true
}
perPackageOption {
prefix = "net.mamoe.mirai.qqandroid.contact"
suppress = true
}
perPackageOption {
prefix = "net.mamoe.mirai.qqandroid.message"
suppress = true
}
perPackageOption {
prefix = "net.mamoe.mirai.qqandroid.network"
suppress = true
}
}
}
}
}
}
2020-05-06 14:00:32 +08:00
fun Project.findLatestFile(): Map.Entry<String, File> {
return File(projectDir, "build/libs").walk()
.filter { it.isFile }
.onEach { println("all files=$it") }
2020-05-06 14:00:32 +08:00
.filter { it.name.matches(Regex("""${project.name}-[0-9][0-9]*(\.[0-9]*)*.*\.jar""")) }
.onEach { println("matched file: ${it.name}") }
.associateBy { it.nameWithoutExtension.substringAfterLast('-') }
.onEach { println("versions: $it") }
2020-05-24 16:42:42 +08:00
.maxBy { (version, _) ->
2020-05-06 14:00:32 +08:00
version.split('.').let {
if (it.size == 2) it + "0"
else it
}.reversed().foldIndexed(0) { index: Int, acc: Int, s: String ->
acc + 100.0.pow(index).toInt() * (s.toIntOrNull() ?: 0)
}
2020-05-06 14:00:32 +08:00
} ?: error("cannot find any file to upload")
2020-05-10 01:11:57 +08:00
}