Mixing Java And Kotlin In Gradle Project, Kotlin Cannot Find Java Class

I had a similar issue and my java code was in the same source directory as the kotlin code

My solution was adding this configuration in build.gradle.kts:

configure<SourceSetContainer> {
    named("main") {
        java.srcDir("src/main/kotlin")
    }
}

you should override sourceSets like this

sourceSets {
    main.java.srcDirs = []
    main.kotlin.srcDirs = ['src/main/java', 'src/main/kotlin']
    main.resources.srcDirs = ['src/main/resources']
}