[英]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:我想在同一个文件夹中包含 kotlin 和 java 文件,例如:
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
.我不在乎
xxx
是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?我如何在 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. a) 因为某些 Gradle DSL 是 Java 或 Kotlin 特定的。
b) the test-runners do not care about other technologies. b) 测试运行者不关心其他技术。
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.但在这种情况下,它绕过了它 - 因为它允许另一个
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']
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.