Add mainCapabilityAttribute to disambiguate project dependencies with multiple capabilities when bundling library jars

This commit is contained in:
Jason Penilla 2024-09-28 21:01:24 -07:00
parent 91fac7484b
commit 833ca1def7
No known key found for this signature in database
GPG key ID: 0E75A301420E48F8
2 changed files with 11 additions and 3 deletions

View file

@ -200,9 +200,14 @@ abstract class CreateBundlerJar : ZippedTask() {
return when (val ident = id.componentIdentifier) { return when (val ident = id.componentIdentifier) {
is ModuleComponentIdentifier -> ModuleId.fromIdentifier(id) is ModuleComponentIdentifier -> ModuleId.fromIdentifier(id)
is ProjectComponentIdentifier -> { is ProjectComponentIdentifier -> {
val capability = variant.capabilities.first() val mainCap = variant.attributes.getAttribute(mainCapabilityAttribute)
val version = capability.version ?: throw PaperweightException("Unknown version for ${capability.group}:${capability.name}") if (mainCap != null) {
ModuleId(capability.group, capability.name, version) 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}") else -> throw PaperweightException("Unknown artifact result type: ${ident::class.java.name}")
} }

View file

@ -53,6 +53,7 @@ import kotlin.io.path.*
import org.cadixdev.lorenz.merge.MergeResult import org.cadixdev.lorenz.merge.MergeResult
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.attributes.Attribute
import org.gradle.api.file.FileCollection import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileSystemLocation import org.gradle.api.file.FileSystemLocation
import org.gradle.api.file.ProjectLayout 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) } path.outputStream().buffered().use { mf.write(it) }
} }
} }
val mainCapabilityAttribute: Attribute<String> = Attribute.of("io.papermc.paperweight.main-capability", String::class.java)