Skip to content

Generated metadata class names can exceed filesystem limits causing build failures #334

@mandor51

Description

@mandor51

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:

  1. Create class with long package name: com.mycompany.myapplication.feature.beforeactivation.internal.presentation.BeforeActivationContainer
  2. add adnotation @Scoped, @scope(NavigationContainerScope.class), @qualifier(BeforeActivationContainer::class)
  3. Build on Windows or MacOS
  4. 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:

  1. use @nAmed annotation but I prefer @qualifier for better type safety.
  2. shorten packages or class name, but in large project it can be not always possible

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions