-
- Notifications
You must be signed in to change notification settings - Fork 67
Description
Describe the bug
When combining @Scoped, @qualifier(Self::class) and @scope annotations, KSP generates metadata class names that exceed filesystem limits (255 characters on Windows or MacOS), causing build failure.
To Reproduce
Steps to reproduce the behavior:
- Create class with long package name: com.mycompany.myapplication.feature.beforeactivation.internal.presentation.BeforeActivationContainer
- add adnotation @Scoped, @scope(NavigationContainerScope.class), @qualifier(BeforeActivationContainer::class)
- Build on Windows or MacOS
- Build fails with filesystem error:
error while writing /projectpath/module/build/tmp/kotlin-classes/debug/org/koin/ksp/generated/_KSP_ComMycompanyMyapplicationFeatureBeforeActivationPresentationInternalBeforeActivationBeforeActivationContainer_Q_ComMycompanyMyapplicationFeatureBeforeActivationInternalPresentationBeforeActivationBeforeActivationContainer_S_ComJermeyQuoVadisFlowmviNavigationContainerScope.class
filnename is 284 characters.
Expected behavior
Generated filename should stay within system limits.
Koin project used and used version (please complete the following information):
koin-core version 4.1.1
koin-annotations version 2.3.1
koin-ksp-compiler version 2.3.1
Root cause analysis in:
https://github.com/InsertKoinIO/koin-annotations/blob/main/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/metadata/tag/TagFactory.kt
the tag concatenates full qualified names:
fun generateTag(definition: KoinMetaData.Definition, dep: KoinMetaData.DefinitionParameter.Dependency, clazz: KSDeclaration): String {
return with(definition) {
listOfNotNull(
clazz.qualifiedName?.asString() ?: "",
qualifier?.let { "$QUALIFIER_SYMBOL${escapeTagClass(it)}" },
scope?.getTagValue()?.camelCase()?.let { "$SCOPE_SYMBOL$it" },
if (isExpect) "Expect" else null,
if (isActual) "Actual" else null
).joinToString(prefix = "${dep.name}:", separator = KOIN_TAG_SEPARATOR)
}
}
As I understand this class name is used only for classpath discovery. All metadata is stored in @MetadataDefinition annotation?
Maybe it is safe tu use SHA as filename, that would elminate that problem completly?
There are workarounds:
- use @nAmed annotation but I prefer @qualifier for better type safety.
- shorten packages or class name, but in large project it can be not always possible