mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 08:50:15 +08:00
Fix build
This commit is contained in:
parent
e0c1600001
commit
9fb167ee60
@ -1,5 +1,3 @@
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.4-M2"
|
kotlin("jvm") version "1.4-M2"
|
||||||
kotlin("plugin.serialization") version "1.4-M2"
|
kotlin("plugin.serialization") version "1.4-M2"
|
||||||
@ -23,21 +21,5 @@ kotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api(kotlin("stdlib-jdk8", "1.4-M2"))
|
api(kotlin("stdlib-jdk8"))
|
||||||
}
|
|
||||||
|
|
||||||
val compileKotlin: KotlinCompile by tasks
|
|
||||||
compileKotlin.kotlinOptions {
|
|
||||||
jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
val compileTestKotlin: KotlinCompile by tasks
|
|
||||||
compileTestKotlin.kotlinOptions {
|
|
||||||
jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
java {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
}
|
|
||||||
tasks.withType(JavaCompile::class.java) {
|
|
||||||
options.encoding = "UTF8"
|
|
||||||
}
|
}
|
@ -8,8 +8,8 @@ allprojects {
|
|||||||
group = "net.mamoe"
|
group = "net.mamoe"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
|
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
|
||||||
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
|
|
||||||
jcenter()
|
jcenter()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
@ -18,5 +18,7 @@ allprojects {
|
|||||||
subprojects {
|
subprojects {
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
apply<MiraiConsoleBuildPlugin>()
|
apply<MiraiConsoleBuildPlugin>()
|
||||||
|
|
||||||
|
setJavaCompileTarget()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -28,8 +28,10 @@ dependencies {
|
|||||||
api(ktor("client-cio", "1.3.2"))
|
api(ktor("client-cio", "1.3.2"))
|
||||||
api(ktor("client-json", "1.3.2"))
|
api(ktor("client-json", "1.3.2"))
|
||||||
|
|
||||||
api(gradleApi())
|
//api(gradleApi())
|
||||||
|
//compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
|
||||||
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
|
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
|
||||||
|
//runtimeOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72")
|
||||||
|
|
||||||
api("com.github.jengelman.gradle.plugins:shadow:6.0.0")
|
api("com.github.jengelman.gradle.plugins:shadow:6.0.0")
|
||||||
}
|
}
|
45
buildSrc/src/main/kotlin/SetCompileTargetPlugin.kt
Normal file
45
buildSrc/src/main/kotlin/SetCompileTargetPlugin.kt
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
import org.gradle.api.JavaVersion
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.plugins.JavaPluginExtension
|
||||||
|
import org.gradle.api.tasks.compile.JavaCompile
|
||||||
|
import java.lang.reflect.Method
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
|
||||||
|
fun Any.reflectMethod(name: String, vararg params: KClass<out Any>): Pair<Any, Method> {
|
||||||
|
return this to this::class.java.getMethod(name, *params.map { it.java }.toTypedArray())
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun Pair<Any, Method>.invoke(vararg args: Any?): Any? {
|
||||||
|
return second.invoke(first, *args)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE") // or error
|
||||||
|
fun Project.setJavaCompileTarget() {
|
||||||
|
tasks.filter { it.name in arrayOf("compileKotlin", "compileTestKotlin") }.forEach { task ->
|
||||||
|
task
|
||||||
|
.reflectMethod("getKotlinOptions")()!!
|
||||||
|
.reflectMethod("setJvmTarget", String::class)("1.8")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
kotlin.runCatching { // apply only when java plugin is available
|
||||||
|
(extensions.getByName("java") as JavaPluginExtension).run {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile::class.java) {
|
||||||
|
options.encoding = "UTF8"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,3 @@
|
|||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version Versions.kotlin
|
kotlin("jvm") version Versions.kotlin
|
||||||
kotlin("plugin.serialization") version Versions.kotlin
|
kotlin("plugin.serialization") version Versions.kotlin
|
||||||
@ -45,22 +43,6 @@ dependencies {
|
|||||||
testApi(project(":mirai-console"))
|
testApi(project(":mirai-console"))
|
||||||
}
|
}
|
||||||
|
|
||||||
version = Versions.Mirai.consolePure
|
version = Versions.consolePure
|
||||||
|
|
||||||
description = "Console Pure CLI frontend for mirai"
|
description = "Console Pure CLI frontend for mirai"
|
||||||
|
|
||||||
val compileKotlin: KotlinCompile by tasks
|
|
||||||
compileKotlin.kotlinOptions {
|
|
||||||
jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
val compileTestKotlin: KotlinCompile by tasks
|
|
||||||
compileTestKotlin.kotlinOptions {
|
|
||||||
jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
java {
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
|
||||||
}
|
|
||||||
tasks.withType(JavaCompile::class.java) {
|
|
||||||
options.encoding = "UTF8"
|
|
||||||
}
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
#Wed Mar 04 22:27:09 CST 2020
|
#Wed Mar 04 22:27:09 CST 2020
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
repositories {
|
repositories {
|
||||||
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
|
mavenLocal()
|
||||||
maven(url = "https://mirrors.huaweicloud.com/repository/maven")
|
|
||||||
jcenter()
|
jcenter()
|
||||||
|
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11,6 +11,8 @@ pluginManagement {
|
|||||||
val version = requested.version
|
val version = requested.version
|
||||||
when (requested.id.id) {
|
when (requested.id.id) {
|
||||||
"org.jetbrains.kotlin.jvm" -> useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${version}")
|
"org.jetbrains.kotlin.jvm" -> useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${version}")
|
||||||
|
"org.jetbrains.kotlin.plugin.serialization" -> useModule("org.jetbrains.kotlin:kotlin-serialization:${version}")
|
||||||
|
"com.jfrog.bintray" -> useModule("com.jfrog.bintray.gradle:gradle-bintray-plugin:$version")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,50 +20,34 @@ pluginManagement {
|
|||||||
|
|
||||||
rootProject.name = "mirai-console"
|
rootProject.name = "mirai-console"
|
||||||
|
|
||||||
val onlyBackEnd = true
|
val disableOldFrontEnds = true
|
||||||
|
|
||||||
include(":mirai-console")
|
fun includeProject(projectPath: String, path: String? = null) {
|
||||||
project(":mirai-console").projectDir = file("backend/mirai-console")
|
include(projectPath)
|
||||||
|
if (path != null) project(projectPath).projectDir = file(path)
|
||||||
|
}
|
||||||
|
|
||||||
include(":codegen")
|
includeProject(":mirai-console", "backend/mirai-console")
|
||||||
project(":codegen").projectDir = file("backend/codegen")
|
includeProject(":codegen", "backend/codegen")
|
||||||
|
includeProject(":mirai-console-pure", "frontend/mirai-console-pure")
|
||||||
|
|
||||||
@Suppress("ConstantConditionIf")
|
@Suppress("ConstantConditionIf")
|
||||||
if (!onlyBackEnd) {
|
if (!disableOldFrontEnds) {
|
||||||
|
includeProject(":mirai-console-terminal", "frontend/mirai-console-terminal")
|
||||||
|
|
||||||
include(":mirai-console-pure")
|
val jdkVersion = kotlin.runCatching {
|
||||||
project(":mirai-console-pure").projectDir = file("frontend/mirai-console-pure")
|
System.getProperty("java.version").let { v ->
|
||||||
|
v.toIntOrNull() ?: v.removePrefix("1.").substringBefore("-").toIntOrNull()
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
}.getOrNull() ?: -1
|
||||||
|
|
||||||
} catch (ignored: Exception) {
|
println("JDK version: $jdkVersion")
|
||||||
println("无法确定 JDK 版本, 将不会引入 `:mirai-console-graphical`")
|
|
||||||
|
if (jdkVersion >= 9) {
|
||||||
|
includeProject(":mirai-console-graphical", "frontend/mirai-console-graphical")
|
||||||
|
} else {
|
||||||
|
println("当前使用的 JDK 版本为 ${System.getProperty("java.version")}, 请使用 JDK 9 以上版本引入模块 `:mirai-console-graphical`\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enableFeaturePreview("GRADLE_METADATA")
|
enableFeaturePreview("GRADLE_METADATA")
|
Loading…
Reference in New Issue
Block a user