h0tk3y
05/24/2019, 12:05 PMjvm { ... }
targets ignored Java sources and did not apply the Gradle java
plugin, which prevented them from proper interoperation with other plugins supporting Java, like the application
plugin.
Now you can configure a JVM target to work with Java, meaning that it will apply the Java plugin to compile Java and setup the model that other plugins may expect. To do that, call withJava()
in the scope of a JVM target, for example:
kotlin {
jvm {
withJava()
/* ... */
}
}
Note that it is disabled by default.
The compilations of such a JVM target are associated with the Java source sets. Kotlin source sets with common code still cannot contain Java.
The Java sources must be placed in sibling directories of the Kotlin source roots. For example, with the default JVM target name `jvm`:
src
├── jvmMain
│ ├── java // production Java sources
│ ├── kotlin
│ └── resources
├── jvmTest
│ ├── java // test Java sources
│ ├── kotlin
… └── resources
There are certain limitations at this point; for example, the Java plugin's tasks jar
and test
are disabled in favor of the JVM target's ones.
As the design is not yet finalized, your feedback is more than welcome!
Known issues can be found in https://youtrack.jetbrains.com/issue/KT-26256, see the related tickets.