[build] Fix dependency exclusion for builds when IDEA_ACTIVE

This commit is contained in:
Him188 2022-11-27 15:09:20 +00:00
parent 7830207b81
commit 3360347ca2
5 changed files with 29 additions and 21 deletions

View File

@ -18,7 +18,6 @@ import org.gradle.kotlin.dsl.accessors.runtime.addDependencyTo
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.invoke
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import java.io.File
/**
* # 非常重要的提示 有关 relocation 在看完全部本文前, 不要进行任何操作
@ -97,9 +96,9 @@ object RelocationNotes
*/
fun KotlinDependencyHandler.relocateCompileOnly(
relocatedDependency: RelocatedDependency,
action: ExternalModuleDependency.() -> Unit = {}
): ExternalModuleDependency {
val dependency = compileOnly(relocatedDependency.notation, action)
val dependency = compileOnly(relocatedDependency.notation) {
}
project.relocationFilters.add(
RelocationFilter(
dependency.group!!, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = false,
@ -120,9 +119,10 @@ fun KotlinDependencyHandler.relocateCompileOnly(
fun DependencyHandler.relocateCompileOnly(
project: Project,
relocatedDependency: RelocatedDependency,
action: Action<ExternalModuleDependency> = Action {}
): Dependency {
val dependency = addDependencyTo(this, "compileOnly", relocatedDependency.notation, action)
val dependency =
addDependencyTo(this, "compileOnly", relocatedDependency.notation, Action<ExternalModuleDependency> {
})
project.relocationFilters.add(
RelocationFilter(
dependency.group!!, dependency.name, relocatedDependency.packages.toList(), includeInRuntime = false,
@ -159,8 +159,7 @@ fun KotlinDependencyHandler.relocateImplementation(
relocatedDependency.notation,
Action<ExternalModuleDependency> {
relocatedDependency.exclusionAction(this)
exclude(ExcludeProperties.`everything from kotlin`)
exclude(ExcludeProperties.`everything from kotlinx`)
intrinsicExclusions()
action()
}
)
@ -182,10 +181,6 @@ fun DependencyHandler.relocateImplementation(
): ExternalModuleDependency {
val dependency =
addDependencyTo(this, "implementation", relocatedDependency.notation, Action<ExternalModuleDependency> {
relocatedDependency.exclusionAction(this)
exclude(ExcludeProperties.`everything from kotlin`)
exclude(ExcludeProperties.`everything from kotlinx`)
action.execute(this)
})
project.relocationFilters.add(
RelocationFilter(
@ -199,14 +194,18 @@ fun DependencyHandler.relocateImplementation(
relocatedDependency.notation,
Action<ExternalModuleDependency> {
relocatedDependency.exclusionAction(this)
exclude(ExcludeProperties.`everything from kotlin`)
exclude(ExcludeProperties.`everything from kotlinx`)
intrinsicExclusions()
action(this)
}
)
return dependency
}
private fun ExternalModuleDependency.intrinsicExclusions() {
exclude(ExcludeProperties.`everything from kotlin`)
exclude(ExcludeProperties.`everything from kotlinx`)
}
const val SHADOW_RELOCATION_CONFIGURATION_NAME = "shadowRelocation"

View File

@ -43,7 +43,7 @@ kotlin {
implementation(project(":mirai-core-utils"))
implementation(project(":mirai-console-compiler-annotations"))
implementation(`kotlinx-serialization-protobuf`)
relocateCompileOnly(`ktor-io_relocated`) // runtime from mirai-core-utils
compileOnly(`ktor-io`) // runtime from mirai-core-utils
}
}
@ -63,7 +63,6 @@ kotlin {
}
findByName("androidMain")?.apply {
dependsOn(commonMain)
dependencies {
compileOnly(`android-runtime`)
}

View File

@ -36,10 +36,7 @@ kotlin {
api(`kotlinx-coroutines-core`)
implementation(`kotlinx-serialization-protobuf`)
relocateImplementation(`ktor-io_relocated`) {
exclude(ExcludeProperties.`kotlin-stdlib`)
exclude(ExcludeProperties.`kotlinx-coroutines`)
}
relocateImplementation(`ktor-io_relocated`)
}
}

View File

@ -73,7 +73,6 @@ kotlin {
}
findByName("androidMain")?.apply {
dependsOn(commonMain)
dependencies {
compileOnly(`android-runtime`)
}

View File

@ -98,7 +98,20 @@ fun generateBuildConfig() {
}
}
// keep this property for Search Everywhere
/**
* Kind note: To run this task you probably need a lot of host memory and luck.
*
* **If you see errors, don't panic, that's most probably not your fault.**
*
* Try:
*
* ```shell
* ./gradlew :mirai-deps-test:updateProjectVersionForLocalDepsTest
* ./gradlew clean :mirai-deps-test:publishMiraiArtifactsToMavenLocal "-Porg.gradle.parallel=false"
* ```
* Note this will change your project version in `buildSrc/src/main/kotlin/Versions.kt`. Be careful to change it back before committing!
* Note also this is **extremely slow**. If your computer isn't good enough it may take hours.
*/
val publishMiraiLocalArtifacts = tasks.register("publishMiraiLocalArtifacts", Exec::class) {
group = "mirai"
description = "Starts a child process to publish v$DEPS_TEST_VERSION artifacts to MavenLocal"
@ -107,6 +120,7 @@ val publishMiraiLocalArtifacts = tasks.register("publishMiraiLocalArtifacts", Ex
environment("mirai.build.project.version", DEPS_TEST_VERSION)
commandLine(
"./gradlew",
"clean",
publishMiraiArtifactsToMavenLocal.name,
"--no-daemon",
"--stacktrace",