As I said, I’m not fluent in kotlin. TBH I find the source quite ugly but that’s just me.
I’m assuming you’ll need two compile tasks in the service project. One for src/main/kotlin
and another for the allgenerated
sources.
I’m also assuming that the kotlin plugin works in the same way as the java plugin. Which means if you add another SourceSet
that it will automatically add a KotlinCompile
task to the model.
So perhaps you could do:
project(':service') {
configurations {
allgenerated
}
sourceSets {
allgenerated { // this adds a SourceSet which adds the compileAllgeneratedKotlin task to the model
kotlin.srcDir "$buildDir/allgenerated"
}
}
dependencies {
// as above
}
// compile tasks usually work with directories so
// might need to copy the configuration to a known directory
task copyAllGenerated(type:Copy) {
from configurations.allgenerated
into "$buildDir/allgenerated"
}
// wire the copy task into the DAG
// task name might be different
compileAllgeneratedKotlin.dependsOn 'copyAllGenerated'
}
Or perhaps you want the extra compile step in each of the subprojects? And the service project collects the class files and builds a jar?
Eg
project(':a') {
configurations { generated }
sourceSets {
generated {
kotlin.srcDir "$buildDir/generated"
}
}
dependencies {
generated tasks.compileGeneratedKotlin
}
task generate {
outputs.dir "$buildDir/generated"
...
}
compileGeneratedKotlin.dependsOn 'generate'
...
}
I think the second approach is cleaner since the extra copy task isn’t required (the directory is “known” to the compile tasks since generate and compile are in the same project)