piotrek
piotrek

Reputation: 14520

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?

Upvotes: 5

Views: 1239

Answers (2)

Martin Zeitler
Martin Zeitler

Reputation: 76569

= 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.

Upvotes: 1

birneee
birneee

Reputation: 663

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']
}

Upvotes: 1

Related Questions