I currently use the following gradle code in my root build.gradle, where I can place the module-info.java under src/module
if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
subprojects {
def moduleInfo = file("${project.projectDir}/src/module/module-info.java")
if (moduleInfo.exists()) {
sourceSets {
module {
java {
srcDirs = ['src/module']
compileClasspath = main.compileClasspath
sourceCompatibility = '9'
targetCompatibility = '9'
}
}
main {
kotlin { srcDirs += ['src/module'] }
}
}
compileModuleJava.configure {
dependsOn compileKotlin
destinationDir = compileKotlin.destinationDir
doFirst {
options.compilerArgs = ['--module-path', classpath.asPath,]
classpath = files()
}
}
jar.dependsOn compileModuleJava
}
}
}
Edit: I added src/module
to the source of main.kotlin in order that the kotlin compiler analyses the module-info.java and complains if necessary.
@ilya.gorbunov when is kotlin turning its jars into modules? I currently get the following warning because I do not want to specify kotlin.stlib for every module:
warning: requires transitive directive for an automatic module
requires transitive kotlin.stdlib;