2020-11-01 15:07:32 +08:00
/*
* Copyright 2019-2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
2019-12-23 19:31:13 +08:00
@file:Suppress("UNUSED_VARIABLE")
2020-12-18 15:37:13 +08:00
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
2019-12-23 19:31:13 +08:00
plugins {
kotlin("multiplatform")
id("kotlinx-atomicfu")
2020-03-24 10:01:03 +08:00
kotlin("plugin.serialization")
2020-10-03 12:42:13 +08:00
id("signing")
2020-08-18 22:09:05 +08:00
id("net.mamoe.kotlin-jvm-blocking-bridge")
2019-12-23 19:31:13 +08:00
`maven-publish`
2020-09-22 18:56:27 +08:00
id("com.jfrog.bintray")
2019-12-23 19:31:13 +08:00
}
2020-10-03 12:42:13 +08:00
description = "Mirai API module"
2019-12-23 19:31:13 +08:00
2020-01-05 18:16:11 +08:00
val isAndroidSDKAvailable: Boolean by project
2020-11-22 14:25:49 +08:00
afterEvaluate {
tasks.getByName("compileKotlinCommon").enabled = false
tasks.getByName("compileTestKotlinCommon").enabled = false
tasks.getByName("compileCommonMainKotlinMetadata").enabled = false
tasks.getByName("compileKotlinMetadata").enabled = false
}
2019-12-23 19:31:13 +08:00
kotlin {
2020-10-03 12:42:13 +08:00
explicitApi()
2020-01-05 17:38:46 +08:00
if (isAndroidSDKAvailable) {
2020-01-21 14:49:42 +08:00
apply(from = rootProject.file("gradle/android.gradle"))
2020-01-05 17:18:02 +08:00
android("android") {
publishAllLibraryVariants()
2019-12-23 19:31:13 +08:00
}
2020-01-05 17:18:02 +08:00
} else {
println(
"""Android SDK 可能未安装.
$name 的 Android 目标编译将不会进行.
2020-01-05 17:38:46 +08:00
这不会影响 Android 以外的平台的编译.
""".trimIndent()
)
println(
"""Android SDK might not be installed.
Android target of $name will not be compiled.
It does no influence on the compilation of other platforms.
2020-01-05 17:18:02 +08:00
""".trimIndent()
)
2019-12-23 19:31:13 +08:00
}
2020-11-22 14:25:49 +08:00
jvm("common") {
2020-12-18 15:37:13 +08:00
attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.common)
2019-12-23 19:31:13 +08:00
}
2020-12-18 15:37:13 +08:00
jvm("jvm")
2020-11-22 14:25:49 +08:00
// jvm("android") {
// attributes.attribute(Attribute.of("mirai.target.platform", String::class.java), "android")
// }
2020-10-03 13:35:05 +08:00
sourceSets {
2020-04-15 18:18:59 +08:00
val commonMain by getting {
2019-12-23 19:31:13 +08:00
dependencies {
2020-12-02 09:25:25 +08:00
implementation(project(":mirai-core-utils"))
2020-10-03 12:42:13 +08:00
api(kotlin("serialization"))
api(kotlin("reflect"))
2020-10-03 13:35:05 +08:00
api1(`kotlinx-serialization-core`)
2020-11-22 14:25:49 +08:00
api1(`kotlinx-serialization-json`)
2020-10-03 13:35:05 +08:00
implementation1(`kotlinx-serialization-protobuf`)
2020-11-30 23:30:57 +08:00
api1(`kotlinx-io-jvm`)
api1(`kotlinx-coroutines-io-jvm`)
2020-10-03 13:35:05 +08:00
api(`kotlinx-coroutines-core`)
2020-10-03 12:42:13 +08:00
2020-10-03 13:35:05 +08:00
implementation1(`kotlinx-atomicfu`)
2020-03-24 10:01:03 +08:00
2020-10-03 13:35:05 +08:00
api1(`ktor-client-cio`)
api1(`ktor-client-core`)
api1(`ktor-network`)
2020-11-30 23:30:57 +08:00
compileOnly(`log4j-api`)
compileOnly(slf4j)
2019-12-23 19:31:13 +08:00
}
}
2020-01-05 18:16:11 +08:00
if (isAndroidSDKAvailable) {
2020-10-03 13:35:05 +08:00
androidMain {
2020-01-05 18:16:11 +08:00
dependencies {
2020-10-03 13:35:05 +08:00
api1(`ktor-client-android`)
2020-01-05 18:16:11 +08:00
}
2019-12-23 19:31:13 +08:00
}
}
2020-11-30 23:30:57 +08:00
val jvmMain by getting
2019-12-23 19:31:13 +08:00
val jvmTest by getting {
dependencies {
2020-10-03 13:35:05 +08:00
api("org.pcap4j:pcap4j-distribution:1.8.2")
2020-10-03 12:42:13 +08:00
runtimeOnly(files("build/classes/kotlin/jvm/test")) // classpath is not properly set by IDE
2019-12-23 19:31:13 +08:00
}
}
}
2020-02-16 13:54:42 +08:00
}
2020-02-18 13:03:51 +08:00
2020-10-03 13:35:05 +08:00
val NamedDomainObjectContainer<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>.androidMain: NamedDomainObjectProvider<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>
get() = named<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>("androidMain")
val NamedDomainObjectContainer<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>.androidTest: NamedDomainObjectProvider<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>
get() = named<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>("androidTest")
val NamedDomainObjectContainer<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>.jvmMain: NamedDomainObjectProvider<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>
get() = named<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>("jvmMain")
val NamedDomainObjectContainer<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>.jvmTest: NamedDomainObjectProvider<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>
get() = named<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>("jvmTest")
2020-08-22 12:56:41 +08:00
fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.implementation1(dependencyNotation: String) =
implementation(dependencyNotation) {
exclude("org.jetbrains.kotlin", "kotlin-stdlib")
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-common")
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-metadata")
}
fun org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler.api1(dependencyNotation: String) =
api(dependencyNotation) {
exclude("org.jetbrains.kotlin", "kotlin-stdlib")
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core")
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-common")
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-jvm")
exclude("org.jetbrains.kotlinx", "kotlinx-coroutines-core-metadata")
}
2020-02-16 13:54:42 +08:00
apply(from = rootProject.file("gradle/publish.gradle"))
2020-08-18 09:24:44 +08:00
tasks.withType<com.jfrog.bintray.gradle.tasks.BintrayUploadTask> {
doFirst {
publishing.publications
.filterIsInstance<MavenPublication>()
.forEach { publication ->
val moduleFile = buildDir.resolve("publications/${publication.name}/module.json")
if (moduleFile.exists()) {
2020-08-19 09:32:56 +08:00
publication.artifact(object :
org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact(moduleFile) {
2020-08-18 09:24:44 +08:00
override fun getDefaultExtension() = "module"
})
}
}
}
}