简体   繁体   中英

Gradle: how to keep kotlin and java in the same source folder?

I would like to have kotlin and java files in the same folder like:

src/main/xxx/JavaClass.java
src/main/xxx/KotlinClass.kt

src/test/xxx/JavaTestClass.java
src/test/xxx/KotlinTestClass.kt

i don't care if xxx is kotlin , java , whatever . i just want to have all the files providing a single functionality in one place with working cross-references / cross-compilation.

how can i configure it in gradle?

= is the wrong operator; += can be used to extend the class-path.

sourceSets {
    main.java.srcDirs += "src/main/kotlin"
}

referencing a separate module is still more solid than within the same module:

a) because some Gradle DSL is Java or Kotlin specific.

b) the test-runners do not care about other technologies.

adding more complexity (a library module) barely solves a problem; but in this case, it circumvents it - because it permits another one build.gradle & test-runner. which otherwise would not be possible.

this should work

sourceSets {
    main.java.srcDirs = ['src/main/xxx']
    main.kotlin.srcDirs = ['src/main/xxx']
    test.java.srcDirs = ['src/test/xxx']
    test.kotlin.srcDirs = ['src/test/xxx']
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM