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?
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']
}
=
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With