mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-04 07:44:42 +08:00
Fix shadowing libraries that another used; fix #2070
This commit is contained in:
parent
75fea25e38
commit
8de404a69a
@ -387,6 +387,58 @@ class TestBuildPlugin : AbstractTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Ktor 2.x available")
|
||||
fun `ktor 2_x`() {
|
||||
tempDir.resolve("build.gradle").appendText(
|
||||
"""
|
||||
dependencies {
|
||||
implementation "io.ktor:ktor-client-core:2.0.0"
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
gradleRunner()
|
||||
.withArguments("buildPlugin", "dependencies", "--stacktrace", "--info")
|
||||
.build()
|
||||
|
||||
ZipFile(findJar()).use { zipFile ->
|
||||
|
||||
val dpPrivate = zipFile.getInputStream(
|
||||
zipFile.getEntry("META-INF/mirai-console-plugin/dependencies-private.txt")
|
||||
).use { it.readBytes().decodeToString() }
|
||||
|
||||
assertTrue { dpPrivate.contains("io.ktor:ktor-client-core:2.0.0") }
|
||||
assertTrue { dpPrivate.contains("io.ktor:ktor-client-core-jvm:2.0.0") }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("can shadow special libraries that another used")
|
||||
fun issue2070() {
|
||||
tempDir.resolve("build.gradle").appendText(
|
||||
"""
|
||||
dependencies {
|
||||
implementation("cn.hutool:hutool-extra:5.8.2")
|
||||
shadowLink("cn.hutool:hutool-core")
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
gradleRunner()
|
||||
.withArguments("buildPlugin", "dependencies", "--stacktrace", "--info")
|
||||
.build()
|
||||
ZipFile(findJar()).use { zipFile ->
|
||||
assertNotNull(zipFile.getEntry("cn/hutool/core/annotation/Alias.class"))
|
||||
|
||||
|
||||
val dpPrivate = zipFile.getInputStream(
|
||||
zipFile.getEntry("META-INF/mirai-console-plugin/dependencies-private.txt")
|
||||
).use { it.readBytes().decodeToString() }
|
||||
|
||||
assertFalse { dpPrivate.contains("hutool-core") }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun findJar(): File = tempDir.resolve("build/mirai").listFiles()!!.first { it.name.endsWith(".mirai2.jar") }
|
||||
|
||||
private fun checkOutput() {
|
||||
@ -409,6 +461,7 @@ class TestBuildPlugin : AbstractTest() {
|
||||
assertTrue { dpPrivate.contains("com.zaxxer:SparseBitSet:1.2") }
|
||||
assertTrue { dpPrivate.contains("com.google.code.gson:gson:2.8.9") }
|
||||
assertFalse { dpPrivate.contains("org.slf4j:slf4j-simple") }
|
||||
assertFalse { dpPrivate.contains("io.ktor") }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -87,8 +87,12 @@ public open class BuildMiraiPluginV2 : Jar() {
|
||||
if (dep is ProjectDependency) {
|
||||
linkedDependencies.add("${dep.group}:${dep.name}")
|
||||
subprojects_linked_fullpath.add(dep.dependencyProject.path)
|
||||
dep.dependencyProject.configurations.findByName("apiElements")?.allDependencies?.forEach { resolve0(it) }
|
||||
dep.dependencyProject.configurations.findByName("implementation")?.allDependencies?.forEach { resolve0(it) }
|
||||
dep.dependencyProject.configurations.findByName("apiElements")?.allDependencies?.forEach {
|
||||
resolve0(it)
|
||||
}
|
||||
dep.dependencyProject.configurations.findByName("implementation")?.allDependencies?.forEach {
|
||||
resolve0(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
resolve0(dep1)
|
||||
@ -143,14 +147,18 @@ public open class BuildMiraiPluginV2 : Jar() {
|
||||
val runtimeClasspath = project.configurations["runtimeClasspath"].resolvedConfiguration
|
||||
fun markAsResolved(resolvedDependency: ResolvedDependency) {
|
||||
val depId = resolvedDependency.depId()
|
||||
linkedDependencies.add(depId)
|
||||
if (depId !in shadowedDependencies) {
|
||||
linkedDependencies.add(depId)
|
||||
}
|
||||
resolvedDependency.children.forEach { markAsResolved(it) }
|
||||
}
|
||||
|
||||
fun linkDependencyTo(resolvedDependency: ResolvedDependency, dependencies: MutableCollection<String>) {
|
||||
|
||||
// bom files
|
||||
if (resolvedDependency.allModuleArtifacts.any { it.extension == "jar" }) {
|
||||
if (resolvedDependency.allModuleArtifacts.any { it.extension == "jar" }) kotlin.run link@{
|
||||
if (resolvedDependency.depId() in shadowedDependencies) return@link
|
||||
|
||||
dependencies.add(resolvedDependency.module.toString())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user