mirai/build.gradle.kts

238 lines
7.7 KiB
Plaintext
Raw Normal View History

2020-11-01 15:07:32 +08:00
/*
2021-01-12 18:57:42 +08:00
* Copyright 2019-2021 Mamoe Technologies and contributors.
2020-11-01 15:07:32 +08:00
*
* 此源代码的使用受 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
*/
2021-01-21 10:08:21 +08:00
@file:Suppress("UnstableApiUsage", "UNUSED_VARIABLE", "NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
2020-03-25 12:18:58 +08:00
2020-09-22 13:23:08 +08:00
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2021-02-01 12:23:04 +08:00
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
2020-10-03 13:35:05 +08:00
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import java.time.LocalDateTime
2020-03-01 13:00:34 +08:00
buildscript {
repositories {
if (System.getProperty("use.maven.local") == "true") {
mavenLocal()
}
2020-10-03 13:35:05 +08:00
mavenCentral()
2021-08-25 14:18:40 +08:00
gradlePluginPortal()
2020-03-01 13:00:34 +08:00
google()
}
dependencies {
2020-10-03 13:35:05 +08:00
classpath("com.android.tools.build:gradle:${Versions.androidGradlePlugin}")
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${Versions.atomicFU}")
classpath("org.jetbrains.kotlinx:binary-compatibility-validator:${Versions.binaryValidator}")
classpath("org.jetbrains.dokka:dokka-base:${Versions.dokka}")
2020-03-01 13:00:34 +08:00
}
}
2020-03-23 19:31:22 +08:00
plugins {
2021-02-01 12:23:04 +08:00
kotlin("jvm") // version Versions.kotlinCompiler
2020-10-03 13:35:05 +08:00
kotlin("plugin.serialization") version Versions.kotlinCompiler
id("org.jetbrains.dokka") version Versions.dokka
2021-02-24 09:16:38 +08:00
// id("org.jetbrains.dokka") version Versions.dokka
2021-01-20 19:25:32 +08:00
id("net.mamoe.kotlin-jvm-blocking-bridge") version Versions.blockingBridge
id("com.gradle.plugin-publish") version "0.12.0" 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
2021-01-21 14:16:03 +08:00
apply(plugin = "binary-compatibility-validator")
configure<kotlinx.validation.ApiValidationExtension> {
allprojects.forEach { subproject ->
ignoredProjects.add(subproject.name)
}
ignoredProjects.remove("binary-compatibility-validator")
ignoredProjects.remove("binary-compatibility-validator-android")
// Enable validator for module `binary-compatibility-validator` and `-android` only.
2021-01-21 14:16:03 +08:00
ignoredPackages.add("net.mamoe.mirai.internal")
ignoredPackages.add("net.mamoe.mirai.console.internal")
2021-06-07 12:16:58 +08:00
nonPublicMarkers.add("net.mamoe.mirai.utils.MiraiInternalApi")
2021-06-07 12:33:31 +08:00
nonPublicMarkers.add("net.mamoe.mirai.utils.MiraiInternalFile")
nonPublicMarkers.add("net.mamoe.mirai.console.utils.ConsoleInternalApi")
nonPublicMarkers.add("net.mamoe.mirai.console.utils.ConsoleExperimentalApi")
2021-06-07 12:16:58 +08:00
nonPublicMarkers.add("net.mamoe.mirai.utils.MiraiExperimentalApi")
2021-01-21 14:16:03 +08:00
}
2020-05-09 15:37:02 +08:00
2021-02-05 17:38:27 +08:00
GpgSigner.setup(project)
2020-04-10 16:13:03 +08:00
analyzes.CompiledCodeVerify.run { registerAllVerifyTasks() }
2020-03-01 13:00:34 +08:00
allprojects {
group = "net.mamoe"
2020-10-03 13:35:05 +08:00
version = Versions.project
2020-03-01 13:00:34 +08:00
repositories {
if (System.getProperty("use.maven.local") == "true") {
mavenLocal()
}
mavenCentral()
2021-08-25 14:18:40 +08:00
gradlePluginPortal()
google()
2020-03-01 13:00:34 +08:00
}
2020-03-25 10:12:24 +08:00
2020-10-03 13:35:05 +08:00
afterEvaluate {
configureJvmTarget()
configureMppShadow()
configureEncoding()
configureKotlinTestSettings()
configureKotlinExperimentalUsages()
2021-01-20 19:25:32 +08:00
runCatching {
blockingBridge {
unitCoercion = net.mamoe.kjbb.compiler.UnitCoercion.COMPATIBILITY
}
2021-01-23 15:22:37 +08:00
}
2021-01-20 19:25:32 +08:00
2020-12-22 20:56:19 +08:00
// useIr()
2020-10-03 13:35:05 +08:00
if (isKotlinJvmProject) {
configureFlattenSourceSets()
}
configureJarManifest()
substituteDependenciesUsingExpectedVersion()
if (System.getenv("MIRAI_IS_SNAPSHOTS_PUBLISHING") != null) {
project.tasks.filterIsInstance<ShadowJar>().forEach { shadow ->
shadow.enabled = false // they are too big
}
logger.info("Disabled all shadow tasks.")
}
2021-01-12 18:57:42 +08:00
}
}
2021-01-12 18:57:42 +08:00
subprojects {
afterEvaluate {
if (project.name == "mirai-core-api") configureDokka()
if (project.name == "mirai-console") configureDokka()
}
2020-10-03 13:35:05 +08:00
}
rootProject.configureDokka()
2020-09-22 13:23:08 +08:00
2021-02-03 21:28:04 +08:00
tasks.register("cleanExceptIntellij") {
group = "build"
2021-02-06 22:28:09 +08:00
allprojects.forEach { proj ->
if (proj.name != "mirai-console-intellij") {
// Type mismatch
// proj.tasks.findByName("clean")?.let(::dependsOn)
2021-02-06 22:28:09 +08:00
proj.tasks.findByName("clean")?.let { dependsOn(it) }
2020-09-22 18:56:27 +08:00
}
2020-10-03 13:35:05 +08:00
}
2021-02-03 21:28:04 +08:00
}
2021-01-12 18:57:42 +08:00
extensions.findByName("buildScan")?.withGroovyBuilder {
setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
setProperty("termsOfServiceAgree", "yes")
}
2020-12-22 20:56:19 +08:00
fun Project.useIr() {
kotlinCompilations?.forEach { kotlinCompilation ->
kotlinCompilation.kotlinOptions.freeCompilerArgs += "-Xuse-ir"
2020-10-03 13:35:05 +08:00
}
}
2020-09-22 13:23:08 +08:00
2020-10-03 13:35:05 +08:00
fun Project.configureDokka() {
val isRoot = this@configureDokka == rootProject
if (!isRoot) {
apply(plugin = "org.jetbrains.dokka")
}
tasks.withType<org.jetbrains.dokka.gradle.AbstractDokkaTask>().configureEach {
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
this.footerMessage = """Copyright 2019-${
LocalDateTime.now().year
} <a href="https://github.com/mamoe">Mamoe Technologies</a> and contributors.
Source code:
<a href="https://github.com/mamoe/mirai">GitHub</a>
""".trimIndent()
this.customAssets = listOf(
rootProject.projectDir.resolve("mirai-dokka/frontend/ext.js"),
)
}
}
tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
perPackageOption {
matchingRegex.set("net\\.mamoe\\.mirai\\.*")
skipDeprecated.set(true)
}
for (suppressedPackage in arrayOf(
"""net.mamoe.mirai.internal""",
"""net.mamoe.mirai.internal.message""",
"""net.mamoe.mirai.internal.network""",
"""net.mamoe.mirai.console.internal""",
"""net.mamoe.mirai.console.compiler.common"""
)) {
perPackageOption {
matchingRegex.set(suppressedPackage.replace(".", "\\."))
suppress.set(true)
}
}
}
}
if (isRoot) {
tasks.named<org.jetbrains.dokka.gradle.AbstractDokkaTask>("dokkaHtmlMultiModule").configure {
outputDirectory.set(
rootProject.projectDir.resolve("mirai-dokka/pages/snapshot")
)
}
}
2020-10-03 13:35:05 +08:00
}
2020-09-22 13:23:08 +08:00
2020-10-03 13:35:05 +08:00
fun Project.configureMppShadow() {
val kotlin =
runCatching {
2021-02-01 12:23:04 +08:00
2020-10-03 13:35:05 +08:00
(this as ExtensionAware).extensions.getByName("kotlin") as? KotlinMultiplatformExtension
}.getOrNull() ?: return
2020-03-25 10:12:24 +08:00
2021-02-01 12:23:04 +08:00
if (project.configurations.findByName("jvmRuntimeClasspath") != null) {
val shadowJvmJar by tasks.creating(ShadowJar::class) sd@{
group = "mirai"
archiveClassifier.set("-all")
2020-09-22 13:23:08 +08:00
2021-02-01 12:23:04 +08:00
val compilations =
kotlin.targets.filter { it.platformType == KotlinPlatformType.jvm }
.map { it.compilations["main"] }
2020-09-22 13:23:08 +08:00
2021-02-01 12:23:04 +08:00
compilations.forEach {
dependsOn(it.compileKotlinTask)
from(it.output)
2020-09-22 13:23:08 +08:00
}
2020-10-03 13:35:05 +08:00
2021-02-01 12:23:04 +08:00
from(project.configurations.findByName("jvmRuntimeClasspath"))
this.exclude { file ->
file.name.endsWith(".sf", ignoreCase = true)
}
2021-02-01 12:23:04 +08:00
/*
2020-10-03 13:35:05 +08:00
this.manifest {
this.attributes(
"Manifest-Version" to 1,
"Implementation-Vendor" to "Mamoe Technologies",
"Implementation-Title" to this.name.toString(),
"Implementation-Version" to this.version.toString()
)
}*/
2020-05-24 16:42:42 +08:00
}
2020-10-03 13:35:05 +08:00
}
}