mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-07 16:40:43 +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 findJar(): File = tempDir.resolve("build/mirai").listFiles()!!.first { it.name.endsWith(".mirai2.jar") }
|
||||||
|
|
||||||
private fun checkOutput() {
|
private fun checkOutput() {
|
||||||
@ -409,6 +461,7 @@ class TestBuildPlugin : AbstractTest() {
|
|||||||
assertTrue { dpPrivate.contains("com.zaxxer:SparseBitSet:1.2") }
|
assertTrue { dpPrivate.contains("com.zaxxer:SparseBitSet:1.2") }
|
||||||
assertTrue { dpPrivate.contains("com.google.code.gson:gson:2.8.9") }
|
assertTrue { dpPrivate.contains("com.google.code.gson:gson:2.8.9") }
|
||||||
assertFalse { dpPrivate.contains("org.slf4j:slf4j-simple") }
|
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) {
|
if (dep is ProjectDependency) {
|
||||||
linkedDependencies.add("${dep.group}:${dep.name}")
|
linkedDependencies.add("${dep.group}:${dep.name}")
|
||||||
subprojects_linked_fullpath.add(dep.dependencyProject.path)
|
subprojects_linked_fullpath.add(dep.dependencyProject.path)
|
||||||
dep.dependencyProject.configurations.findByName("apiElements")?.allDependencies?.forEach { resolve0(it) }
|
dep.dependencyProject.configurations.findByName("apiElements")?.allDependencies?.forEach {
|
||||||
dep.dependencyProject.configurations.findByName("implementation")?.allDependencies?.forEach { resolve0(it) }
|
resolve0(it)
|
||||||
|
}
|
||||||
|
dep.dependencyProject.configurations.findByName("implementation")?.allDependencies?.forEach {
|
||||||
|
resolve0(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve0(dep1)
|
resolve0(dep1)
|
||||||
@ -143,14 +147,18 @@ public open class BuildMiraiPluginV2 : Jar() {
|
|||||||
val runtimeClasspath = project.configurations["runtimeClasspath"].resolvedConfiguration
|
val runtimeClasspath = project.configurations["runtimeClasspath"].resolvedConfiguration
|
||||||
fun markAsResolved(resolvedDependency: ResolvedDependency) {
|
fun markAsResolved(resolvedDependency: ResolvedDependency) {
|
||||||
val depId = resolvedDependency.depId()
|
val depId = resolvedDependency.depId()
|
||||||
|
if (depId !in shadowedDependencies) {
|
||||||
linkedDependencies.add(depId)
|
linkedDependencies.add(depId)
|
||||||
|
}
|
||||||
resolvedDependency.children.forEach { markAsResolved(it) }
|
resolvedDependency.children.forEach { markAsResolved(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun linkDependencyTo(resolvedDependency: ResolvedDependency, dependencies: MutableCollection<String>) {
|
fun linkDependencyTo(resolvedDependency: ResolvedDependency, dependencies: MutableCollection<String>) {
|
||||||
|
|
||||||
// bom files
|
// 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())
|
dependencies.add(resolvedDependency.module.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user