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

前端 未结 2 1251
别那么骄傲
别那么骄傲 2021-02-13 01:12

As the title says, I am trying to mix Java and Kotlin in a single project. There\'s a good example found here. mixed-java-kotlin-hello-world. Everything is working properly besi

相关标签:
2条回答
  • 2021-02-13 01:24

    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']
    }
    
    0 讨论(0)
  • 2021-02-13 01:28

    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")
        }
    }
    
    0 讨论(0)
提交回复
热议问题