Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redeclaration errors for @Component when ksp is used for common and target source sets #194

Closed
eygraber opened this issue May 3, 2022 · 4 comments

Comments

@eygraber
Copy link
Contributor

eygraber commented May 3, 2022

I have a component written in commonMain:

@Component
abstract class AppComponent(
  @Component protected val platformComponent: PlatformComponent
) {
  companion object
}

I also have another component written in commonMain as an expect class:

expect abstract class PlatformComponent {
  companion object
}

and an actual class in my targets (e.g. android):

@Component
actual abstract class PlatformComponent(
  @get:Provides val context: AppContext
) {
  actual companion object
}

I set up ksp to run for common and each of my targets:

kotlin.sourceSets.commonMain {
  kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
}

kotlin.targets.configureEach {
  kotlin.configureKsp(name)
}

fun KotlinSourceSetContainer.configureKsp(targetName: String) {
  runCatching {
    dependencies {
      add("ksp${targetName.capitalized()}", libs.kotlinInject.compiler)
    }

    sourceSets.configureEach {
      kotlin.srcDir("build/generated/ksp/$targetName/$name/kotlin")
    }
  }
}

dependencies {
  add("kspCommonMainMetadata", libs.kotlinInject.compiler)

  tasks.withType<KotlinCompile>().configureEach {
    if(name != "kspCommonMainKotlinMetadata") {
      dependsOn("kspCommonMainKotlinMetadata")
    }
  }
}

And I get the following errors:

e: /home/eli/workspace/galgal/core/build/generated/ksp/android/androidDebug/kotlin/com/eygraber/galgal/core/components/InjectAppComponent.kt: (9, 14): Redeclaration: InjectAppComponent

e: /home/eli/workspace/galgal/core/build/generated/ksp/metadata/commonMain/kotlin/com/eygraber/galgal/core/components/InjectAppComponent.kt: (6, 14): Redeclaration: InjectAppComponent
eygraber added a commit to eygraber/kotlin-inject that referenced this issue May 3, 2022
@eygraber
Copy link
Contributor Author

eygraber commented May 3, 2022

@eygraber
Copy link
Contributor Author

eygraber commented May 3, 2022

Looks like this is a ksp issue - google/ksp#965

@eygraber eygraber closed this as completed May 3, 2022
@eygraber
Copy link
Contributor Author

eygraber commented May 6, 2022

Actually looks like there is a hacky workaround mentioned in google/ksp#965

I'll put up a PR with it.

@eygraber
Copy link
Contributor Author

eygraber commented May 6, 2022

Closing again, since waiting for ksp to better support this is the better option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant