Skip to content

Kotlin Compiler Plugin doesn’t bind Java classes #338

Description

@volo

Describe the bug
Koin Compiler Plugin doesn’t generate a proper binding for Java classes

Consider the following class implementing an interface (the interface itself can be either in Java or Kotlin)

@Single
public class JavaImpl implements JavaInterface {

    private final LibraryRepositoryProtocol repository;

    @Inject
    public JavaImpl(LibraryRepositoryProtocol repository) {
        this.repository = repository;
    }
}

This results in the compilation error:

[Koin] Missing dependency: com.tezov.koin_sample.domain.protocol.JavaInterface
required by: com.tezov.koin_sample.domain.usecase.GetFavoriteLibrariesUseCase (parameter 'javaInterface')
in module: AppModule

If the implementation class JavaImpl is converted to Kotlin the issue is fixed and compilation succeeds.

To Reproduce
Steps to reproduce the behavior:

  1. Check out https://github.com/volo-droid/koin-annotations-java-issue/tree/bug-with-koin-compiler
  2. Try to compile it
  3. See the compilation error:
    [Koin] Missing dependency: com.tezov.koin_sample.domain.protocol.JavaInterface
    required by: com.tezov.koin_sample.domain.usecase.GetFavoriteLibrariesUseCase (parameter 'javaInterface')
    in module: AppModule
    

Additional info
KSP also failed to generate a proper constructor binding for a Java class which has a non-default constructor. The class above results in the following generated code and compilation error No value passed for parameter 'repository':

single() { _ -> com.tezov.koin_sample.data.JavaImpl()} bind(com.tezov.koin_sample.domain.protocol.JavaInterface::class)

To Reproduce with KSP check out https://github.com/volo-droid/koin-annotations-java-issue/tree/bug-with-ksp

Expected behavior
Java classes should be picked up by Koin the same way as Kotlin are. If that's not possible, it should be mentioned in the documentation as a known limitation.

Koin project used and used version (please complete the following information):
koin-core version 4.2.0
koin-plugin version 0.4.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions