Rearrange build scripts

This commit is contained in:
Him188 2020-06-20 22:55:07 +08:00
parent 754811ddaa
commit f5d9f4a67e
12 changed files with 225 additions and 216 deletions

View File

@ -1,8 +1,8 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("kotlin")
kotlin("plugin.serialization")
kotlin("jvm") version "1.4-M2"
kotlin("plugin.serialization") version "1.4-M2"
id("java")
}
@ -12,6 +12,8 @@ kotlin {
languageSettings.useExperimentalAnnotation("kotlin.Experimental")
languageSettings.useExperimentalAnnotation("kotlin.OptIn")
languageSettings.progressiveMode = true
languageSettings.languageVersion = "1.4"
languageSettings.apiVersion = "1.4"
languageSettings.useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiInternalAPI")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
languageSettings.useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference")
@ -21,7 +23,7 @@ kotlin {
}
dependencies {
api(kotlin("stdlib"))
api(kotlin("stdlib-jdk8", "1.4-M2"))
}
val compileKotlin: KotlinCompile by tasks

View File

@ -2,16 +2,14 @@ import upload.Bintray
import java.util.*
plugins {
id("kotlin")
kotlin("plugin.serialization")
kotlin("jvm") version Versions.kotlin
kotlin("plugin.serialization") version Versions.kotlin
id("java")
`maven-publish`
id("com.jfrog.bintray")
id("com.jfrog.bintray") version Versions.bintray
}
apply(plugin = "com.github.johnrengelman.shadow")
version = Versions.Mirai.console
version = Versions.console
description = "Console backend for mirai"
java {
@ -56,14 +54,14 @@ kotlin {
}
dependencies {
compileAndRuntime("net.mamoe:mirai-core:${Versions.Mirai.core}")
compileAndRuntime("net.mamoe:mirai-core:${Versions.core}")
compileAndRuntime(kotlin("stdlib"))
api("net.mamoe.yamlkt:yamlkt:0.3.1")
api("org.jetbrains:annotations:19.0.0")
api(kotlinx("coroutines-jdk8", Versions.Kotlin.coroutines))
api(kotlinx("coroutines-jdk8", Versions.coroutines))
testApi("net.mamoe:mirai-core-qqandroid:${Versions.Mirai.core}")
testApi("net.mamoe:mirai-core-qqandroid:${Versions.core}")
testApi(kotlin("stdlib-jdk8"))
testApi(kotlin("test"))
testApi(kotlin("test-junit5"))

View File

@ -1,27 +1,9 @@
@file:Suppress("UnstableApiUsage")
import kotlin.math.pow
tasks.withType(JavaCompile::class.java) {
options.encoding = "UTF8"
}
buildscript {
repositories {
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
jcenter()
mavenCentral()
}
dependencies {
classpath("com.github.jengelman.gradle.plugins:shadow:5.2.0")
classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.Kotlin.stdlib}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.Kotlin.stdlib}")
classpath("com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4") // don"t use any other.
}
}
allprojects {
group = "net.mamoe"
@ -35,97 +17,6 @@ allprojects {
subprojects {
afterEvaluate {
apply(plugin = "com.github.johnrengelman.shadow")
val kotlin =
(this as ExtensionAware).extensions.getByName("kotlin") as? org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
?: return@afterEvaluate
tasks.getByName("shadowJar") {
doLast {
this.outputs.files.forEach {
if (it.nameWithoutExtension.endsWith("-all")) {
val output = File(
it.path.substringBeforeLast(File.separator) + File.separator + it.nameWithoutExtension.substringBeforeLast(
"-all"
) + "." + it.extension
)
println("Renaming to ${output.path}")
if (output.exists()) {
output.delete()
}
it.renameTo(output)
}
}
}
}
val githubUpload by tasks.creating {
group = "mirai"
dependsOn(tasks.getByName("shadowJar"))
doFirst {
timeout.set(java.time.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
}
}
}
}
val cuiCloudUpload by tasks.creating {
group = "mirai"
dependsOn(tasks.getByName("shadowJar"))
doFirst {
timeout.set(java.time.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
}
}
}
}
apply<MiraiConsoleBuildPlugin>()
}
}
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][0-9]*(\.[0-9]*)*.*\.jar""")) }
.onEach { println("matched file: ${it.name}") }
.associateBy { it.nameWithoutExtension.substringAfterLast('-') }
.onEach { println("versions: $it") }
.maxBy { (version, file) ->
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)
}
} ?: error("cannot find any file to upload")
}
}

View File

@ -3,7 +3,10 @@ plugins {
}
repositories {
mavenLocal()
jcenter()
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
mavenCentral()
}
kotlin {
@ -24,4 +27,9 @@ dependencies {
api(ktor("client-core", "1.3.2"))
api(ktor("client-cio", "1.3.2"))
api(ktor("client-json", "1.3.2"))
api(gradleApi())
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
api("com.github.jengelman.gradle.plugins:shadow:6.0.0")
}

View File

@ -0,0 +1,115 @@
/*
* Copyright 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
*/
@file:Suppress("UnstableApiUsage")
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.creating
import java.io.File
import kotlin.math.pow
class MiraiConsoleBuildPlugin : Plugin<Project> {
override fun apply(target: Project) = target.run {
apply<ShadowPlugin>()
if (tasks.none { it.name == "shadowJar" }) {
return@run
}
tasks.getByName("shadowJar") {
doLast {
this.outputs.files.forEach {
if (it.nameWithoutExtension.endsWith("-all")) {
val output = File(
it.path.substringBeforeLast(File.separator) + File.separator + it.nameWithoutExtension.substringBeforeLast(
"-all"
) + "." + it.extension
)
println("Renaming to ${output.path}")
if (output.exists()) {
output.delete()
}
it.renameTo(output)
}
}
}
}
tasks.creating {
group = "mirai"
dependsOn(tasks.getByName("shadowJar"))
doFirst {
timeout.set(java.time.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
}
}
}
}
tasks.creating {
group = "mirai"
dependsOn(tasks.getByName("shadowJar"))
doFirst {
timeout.set(java.time.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
}
}
}
}
}
}
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][0-9]*(\.[0-9]*)*.*\.jar""")) }
.onEach { println("matched file: ${it.name}") }
.associateBy { it.nameWithoutExtension.substringAfterLast('-') }
.onEach { println("versions: $it") }
.maxBy { (version, _) ->
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)
}
} ?: error("cannot find any file to upload")
}

View File

@ -8,18 +8,18 @@
*/
object Versions {
object Mirai {
const val core = "1.0.0"
const val console = "0.5.1"
const val consoleGraphical = "0.0.7"
const val consoleTerminal = "0.1.0"
const val consolePure = "0.1.0"
}
const val core = "1.0.0"
const val console = "0.5.1"
const val consoleGraphical = "0.0.7"
const val consoleTerminal = "0.1.0"
const val consolePure = "0.1.0"
object Kotlin {
const val stdlib = "1.3.72"
const val coroutines = "1.3.7"
const val serialization = "0.20.0"
const val ktor = "1.3.2"
}
const val kotlin = "1.3.72"
const val coroutines = "1.3.7"
const val serialization = "0.20.0"
const val ktor = "1.3.2"
const val androidGradle = "3.6.2"
const val bintray = "1.8.4"
}

View File

@ -5,7 +5,7 @@ import org.gradle.kotlin.dsl.DependencyHandlerScope
fun DependencyHandlerScope.kotlinx(id: String, version: String) = "org.jetbrains.kotlinx:kotlinx-$id:$version"
@Suppress("unused")
fun DependencyHandlerScope.ktor(id: String, version: String = Versions.Kotlin.ktor) = "io.ktor:ktor-$id:$version"
fun DependencyHandlerScope.ktor(id: String, version: String = Versions.ktor) = "io.ktor:ktor-$id:$version"
@Suppress("unused")
fun DependencyHandler.compileAndRuntime(any: Any) {

View File

@ -29,17 +29,17 @@ version = Versions.Mirai.consoleGraphical
description = "Graphical frontend for mirai-console"
dependencies {
compileOnly("net.mamoe:mirai-core:${Versions.Mirai.core}")
compileOnly("net.mamoe:mirai-core:${Versions.core}")
implementation(project(":mirai-console"))
api(group = "no.tornado", name = "tornadofx", version = "1.7.19")
api(group = "com.jfoenix", name = "jfoenix", version = "9.0.8")
testApi(project(":mirai-console"))
testApi(kotlinx("coroutines-core", Versions.Kotlin.coroutines))
testApi(kotlinx("coroutines-core", Versions.coroutines))
testApi(group = "org.yaml", name = "snakeyaml", version = "1.25")
testApi("net.mamoe:mirai-core:${Versions.Mirai.core}")
testApi("net.mamoe:mirai-core-qqandroid:${Versions.Mirai.core}")
testApi("net.mamoe:mirai-core:${Versions.core}")
testApi("net.mamoe:mirai-core-qqandroid:${Versions.core}")
}
kotlin {

View File

@ -27,10 +27,10 @@ kotlin {
}
dependencies {
compileOnly(project(":mirai-console"))
compileOnly("net.mamoe:mirai-core:${Versions.Mirai.core}")
compileOnly("net.mamoe:mirai-core:${Versions.core}")
compileOnly(kotlin("stdlib")) // embedded by core
testApi("net.mamoe:mirai-core-qqandroid:${Versions.Mirai.core}")
testApi("net.mamoe:mirai-core-qqandroid:${Versions.core}")
testApi(project(":mirai-console"))
}

View File

@ -28,7 +28,7 @@ kotlin {
}
dependencies {
compileOnly("net.mamoe:mirai-core-qqandroid:${Versions.Mirai.core}")
compileOnly("net.mamoe:mirai-core-qqandroid:${Versions.core}")
api(project(":mirai-console"))
api(group = "com.googlecode.lanterna", name = "lanterna", version = "3.0.2")
}

View File

@ -1,72 +0,0 @@
pluginManagement {
resolutionStrategy {
eachPlugin {
switch (requested.id.id) {
case "org.jetbrains.kotlin.multiplatform": useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}"); break
case "com.android.library": useModule("com.android.tools.build:gradle:${requested.version}"); break
case "com.jfrog.bintray": useModule("com.jfrog.bintray.gradle:gradle-bintray-plugin:${requested.version}")
}
}
}
repositories {
mavenLocal()
jcenter()
google()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
maven { url 'https://plugins.gradle.org/m2/' }
}
}
rootProject.name = 'mirai-console'
def onlyBackEnd = true
include(':mirai-console')
project(':mirai-console').dir = file("backend/mirai-console")
include(':codegen')
project(':codegen').dir = file("backend/codegen")
if (!onlyBackEnd) {
include(':mirai-console-pure')
project(':mirai-console-pure').dir = file("frontend/mirai-console-pure")
include(':mirai-console-terminal')
project(':mirai-console-terminal').dir = file("frontend/mirai-console-terminal")
try {
def javaVersion = System.getProperty("java.version")
def versionPos = javaVersion.indexOf(".")
def javaVersionNum = javaVersion.substring(0, 1).toInteger()
if (javaVersion.startsWith("1.")) {
javaVersionNum = javaVersion.substring(2, 3).toInteger()
} else {
if (versionPos == -1) versionPos = javaVersion.indexOf("-")
if (versionPos == -1) {
println("jdk version unknown")
} else {
javaVersionNum = javaVersion.substring(0, versionPos).toInteger()
}
}
if (javaVersionNum >= 9) {
include(':mirai-console-graphical')
project(':mirai-console-graphical').dir = file("frontend/mirai-console-graphical")
} else {
println("jdk版本为 " + javaVersionNum)
println("当前使用的 JDK 版本为 ${System.getProperty("java.version")}, 请使用JDK 9以上版本引入模块 `:mirai-console-graphical`\n")
}
} catch (Exception ignored) {
println("无法确定 JDK 版本, 将不会引入 `:mirai-console-graphical`")
}
}
enableFeaturePreview('GRADLE_METADATA')

67
settings.gradle.kts Normal file
View File

@ -0,0 +1,67 @@
pluginManagement {
repositories {
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
jcenter()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
val version = requested.version
when (requested.id.id) {
"org.jetbrains.kotlin.jvm" -> useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${version}")
}
}
}
}
rootProject.name = "mirai-console"
val onlyBackEnd = true
include(":mirai-console")
project(":mirai-console").projectDir = file("backend/mirai-console")
include(":codegen")
project(":codegen").projectDir = file("backend/codegen")
@Suppress("ConstantConditionIf")
if (!onlyBackEnd) {
include(":mirai-console-pure")
project(":mirai-console-pure").projectDir = file("frontend/mirai-console-pure")
include(":mirai-console-terminal")
project(":mirai-console-terminal").projectDir = file("frontend/mirai-console-terminal")
try {
val javaVersion = System.getProperty("java.version")
var versionPos = javaVersion.indexOf(".")
var javaVersionNum = javaVersion.substring(0, 1).toInt()
if (javaVersion.startsWith("1.")) {
javaVersionNum = javaVersion.substring(2, 3).toInt()
} else {
if (versionPos == -1) versionPos = javaVersion.indexOf("-")
if (versionPos == -1) {
println("jdk version unknown")
} else {
javaVersionNum = javaVersion.substring(0, versionPos).toInt()
}
}
if (javaVersionNum >= 9) {
include(":mirai-console-graphical")
project(":mirai-console-graphical").projectDir = file("frontend/mirai-console-graphical")
} else {
println("JDK 版本为 $javaVersionNum")
println("当前使用的 JDK 版本为 ${System.getProperty("java.version")}, 请使用JDK 9以上版本引入模块 `:mirai-console-graphical`\n")
}
} catch (ignored: Exception) {
println("无法确定 JDK 版本, 将不会引入 `:mirai-console-graphical`")
}
}
enableFeaturePreview("GRADLE_METADATA")