[build] Rewrite shadow relocation; fix dependency graph issues with Android, and improve build performance:

- Generate relocated JARs with classifier `relocated`, instead of replacing the output of `:jar` task.

- Create `JvmRelocated` publications to publish relocated artifacts.

- Patch Kotlin Metadata and Maven Pom for the added publication.

- Updated deps test to be more strict
This commit is contained in:
Him188
2023-04-29 15:02:05 +01:00
parent 40d4957837
commit 178ca6c1b5
19 changed files with 683 additions and 359 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@@ -48,16 +48,10 @@ val publishMiraiArtifactsToMavenLocal by tasks.registering {
// Always print this very important message
logger.warn("[publishMiraiArtifactsToMavenLocal] Project version is '${project.version}'.")
}
}
doLast {
// delete shadowed Jars, since Kotlin can't compile modules that depend on them.
rootProject.subprojects
.asSequence()
.flatMap { proj -> proj.tasks.filter { task -> task.name.contains("relocate") } }
.flatMap { it.outputs.files }
.filter { it.isFile && it.name.endsWith(".jar") }
.forEach { it.delete() }
}
tasks.getByName("test") {
mustRunAfter(publishMiraiArtifactsToMavenLocal)
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@@ -33,6 +33,9 @@ abstract class AbstractTest {
@JvmStatic
fun isMiraiLocalAvailable(): Boolean {
val commandLine =
"""./gradlew publishMiraiArtifactsToMavenLocal -Dmirai.build.project.version=$miraiLocalVersion"""
return if (mavenLocalDir.resolve("net/mamoe/mirai-core/$miraiLocalVersion").exists()) {
println(
"""
@@ -41,7 +44,8 @@ abstract class AbstractTest {
- added/removed a dependency for mirai-core series modules
- changed version of any of the dependencies for mirai-core series modules
You can update by running `./gradlew publishMiraiLocalArtifacts`.
You can update by running the following command:
$commandLine
""".trimIndent()
)
true
@@ -58,7 +62,9 @@ abstract class AbstractTest {
Note that you can ignore this test if you did not change project (dependency) structure.
And you don't need to worry if you does not run this test — this test is always executed on the CI when you make a PR.
You can run `./gradlew publishMiraiLocalArtifacts` to publish local artifacts.
You can run the following command to publish local artifacts:
$commandLine
Then you can run this test again. (By your original way or ./gradlew :mirai-deps-test:test)
""".trimIndent()
System.err.println(

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
* Copyright 2019-2023 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.
@@ -117,8 +117,8 @@ class CoreShadowRelocationTest : AbstractTest() {
"""
dependencies {
implementation("net.mamoe:mirai-core:$miraiLocalVersion") {
exclude("net.mamoe", "mirai-core-api")
exclude("net.mamoe", "mirai-core-utils")
exclude("net.mamoe", "mirai-core-api-jvm")
exclude("net.mamoe", "mirai-core-utils-jvm")
}
}
""".trimIndent()
@@ -130,6 +130,7 @@ class CoreShadowRelocationTest : AbstractTest() {
@EnabledIf("isMiraiLocalAvailable", disabledReason = REASON_LOCAL_ARTIFACT_NOT_AVAILABLE)
fun `test mirai-core-api without transitive mirai-core-utils`() {
val fragment = buildTestCases {
-`mirai-core-utils`
-both(`ktor-io`)
-both(`ktor-client-core`)
-both(`ktor-client-okhttp`)
@@ -143,7 +144,7 @@ class CoreShadowRelocationTest : AbstractTest() {
"""
dependencies {
implementation("net.mamoe:mirai-core-api:$miraiLocalVersion") {
exclude("net.mamoe", "mirai-core-utils")
exclude("net.mamoe", "mirai-core-utils-jvm")
}
}
""".trimIndent()
@@ -233,6 +234,7 @@ class CoreShadowRelocationTest : AbstractTest() {
val relocated: (FunctionTestCase.() -> FunctionTestCase)? = null,
)
val `mirai-core-utils` = ClassTestCase("mirai-core-utils Symbol", "net.mamoe.mirai.utils.Symbol")
val `ktor-io` = ClassTestCase("ktor-io ByteBufferChannel", ByteBufferChannel)
val `ktor-client-core` = ClassTestCase("ktor-client-core HttpClient", HttpClient)
val `ktor-client-okhttp` = ClassTestCase("ktor-client-core OkHttp", KtorOkHttp)
@@ -302,7 +304,7 @@ class CoreShadowRelocationTest : AbstractTest() {
result.append(
"""
@Test
fun `no relocated ${name}`() {
fun `no ${name}`() {
assertThrows<ClassNotFoundException> { Class.forName("$qualifiedClassName") }
}
""".trimIndent()