From 833ca1def747454229da5edc15f478bf5bd16a9e Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Sat, 28 Sep 2024 21:01:24 -0700 Subject: [PATCH] Add mainCapabilityAttribute to disambiguate project dependencies with multiple capabilities when bundling library jars --- .../io/papermc/paperweight/tasks/CreateBundlerJar.kt | 11 ++++++++--- .../main/kotlin/io/papermc/paperweight/util/utils.kt | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/CreateBundlerJar.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/CreateBundlerJar.kt index fcef177..5dd61e2 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/CreateBundlerJar.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/tasks/CreateBundlerJar.kt @@ -200,9 +200,14 @@ abstract class CreateBundlerJar : ZippedTask() { return when (val ident = id.componentIdentifier) { is ModuleComponentIdentifier -> ModuleId.fromIdentifier(id) is ProjectComponentIdentifier -> { - val capability = variant.capabilities.first() - val version = capability.version ?: throw PaperweightException("Unknown version for ${capability.group}:${capability.name}") - ModuleId(capability.group, capability.name, version) + val mainCap = variant.attributes.getAttribute(mainCapabilityAttribute) + if (mainCap != null) { + ModuleId.parse(mainCap) + } else { + val capability = variant.capabilities.first() + val version = capability.version ?: throw PaperweightException("Unknown version for ${capability.group}:${capability.name}") + ModuleId(capability.group, capability.name, version) + } } else -> throw PaperweightException("Unknown artifact result type: ${ident::class.java.name}") } diff --git a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt index 961f1dd..fa62d06 100644 --- a/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt +++ b/paperweight-lib/src/main/kotlin/io/papermc/paperweight/util/utils.kt @@ -53,6 +53,7 @@ import kotlin.io.path.* import org.cadixdev.lorenz.merge.MergeResult import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.attributes.Attribute import org.gradle.api.file.FileCollection import org.gradle.api.file.FileSystemLocation import org.gradle.api.file.ProjectLayout @@ -416,3 +417,5 @@ fun modifyManifest(path: Path, create: Boolean = true, op: Manifest.() -> Unit) path.outputStream().buffered().use { mf.write(it) } } } + +val mainCapabilityAttribute: Attribute = Attribute.of("io.papermc.paperweight.main-capability", String::class.java)