mirror of
https://github.com/mamoe/mirai.git
synced 2026-09-05 22:54:55 +08:00
Allow users to override Kotlin version, fix #367
This commit is contained in:
@@ -23,16 +23,18 @@ plugins {
|
||||
|
||||
val integTest = sourceSets.create("integTest")
|
||||
|
||||
/**
|
||||
* Because we use [compileOnly] for `kotlin-gradle-plugin`, it would be missing
|
||||
* in `plugin-under-test-metadata.properties`. Here we inject the jar into TestKit plugin
|
||||
* classpath via [PluginUnderTestMetadata] to avoid [NoClassDefFoundError].
|
||||
*/
|
||||
val kotlinVersionForIntegrationTest: Configuration by configurations.creating
|
||||
|
||||
dependencies {
|
||||
compileOnly(gradleApi())
|
||||
compileOnly(gradleKotlinDsl())
|
||||
api(kotlin("gradle-plugin-api").toString()) {
|
||||
exclude("org.jetbrains.kotlin", "kotlin-stdlib")
|
||||
}
|
||||
api(kotlin("gradle-plugin").toString()) {
|
||||
exclude("org.jetbrains.kotlin", "kotlin-stdlib")
|
||||
}
|
||||
|
||||
compileOnly(kotlin("gradle-plugin-api"))
|
||||
compileOnly(kotlin("gradle-plugin"))
|
||||
compileOnly(kotlin("stdlib"))
|
||||
|
||||
implementation("com.google.code.gson:gson:2.8.6")
|
||||
@@ -52,6 +54,12 @@ dependencies {
|
||||
"integTestImplementation"("org.junit.jupiter:junit-jupiter-engine:${Versions.junit}")
|
||||
// "integTestImplementation"("org.spockframework:spock-core:1.3-groovy-2.5")
|
||||
"integTestImplementation"(gradleTestKit())
|
||||
|
||||
kotlinVersionForIntegrationTest(kotlin("gradle-plugin", "1.5.21"))
|
||||
}
|
||||
|
||||
tasks.named<PluginUnderTestMetadata>("pluginUnderTestMetadata") {
|
||||
pluginClasspath.from(kotlinVersionForIntegrationTest)
|
||||
}
|
||||
|
||||
version = Versions.console
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2019-2021 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/dev/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.console.gradle
|
||||
|
||||
import org.gradle.testkit.runner.GradleRunner
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.io.TempDir
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.PrintWriter
|
||||
|
||||
class KotlinTransitiveDependenciesIntegrationTest {
|
||||
@Test
|
||||
fun `user can override Kotlin plugin version`(@TempDir dir: File) {
|
||||
// We're packaging the plugin with kotlin transitive dependencies > 1.4.30
|
||||
// This is testing that users are free to use different versions
|
||||
val userSpecifiedKotlinPluginVersion = "1.5.21"
|
||||
dir.resolve("settings.gradle").writeText("")
|
||||
dir.resolve("build.gradle").writeText(
|
||||
"""
|
||||
plugins {
|
||||
id 'net.mamoe.mirai-console'
|
||||
id 'org.jetbrains.kotlin.jvm' version '$userSpecifiedKotlinPluginVersion'
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
val stdout = ByteArrayOutputStream()
|
||||
val stderr = ByteArrayOutputStream()
|
||||
|
||||
GradleRunner.create()
|
||||
.withProjectDir(dir)
|
||||
.withGradleVersion("6.8.3")
|
||||
.withPluginClasspath()
|
||||
.forwardStdOutput(PrintWriter(stdout))
|
||||
.forwardStdError(PrintWriter(stderr))
|
||||
.withArguments(listOf("dependencies"))
|
||||
.build()
|
||||
|
||||
System.out.println(stdout)
|
||||
System.err.println(stderr)
|
||||
|
||||
Assertions.assertTrue(
|
||||
stdout.toString()
|
||||
.contains("org.jetbrains.kotlin:kotlin-compiler-embeddable:${userSpecifiedKotlinPluginVersion}")
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user