Gopal S Akshintala
05/23/2021, 4:18 AMsrc/main/java
and Kotlin compiler with ${project.buildDir}/generated/sources/delombok/java/main
?
Problem details and Use-case: I call Kotlin from Java and some Kotlin files use Java classes that are annotated with Lombok. So the idea is (which I followed in Maven as well) is to delombok first to generate sources -> then point Kotlin to use delombok generated sourceSets to prepare end results.
The problem is, when I do this, it appends this sourceSets to src/main/java
(which leads to compile failure)
compileKotlin {
dependsOn(delombok)
sourceSets.main {
java.srcDirs(“${project.buildDir}/generated/sources/delombok/java/main”)
}
}
When I use setSrcDirs
instead of srcDirs
like below, lombok is not able to pick-up java files from src/main/java
(this is strange as I only have set it up in compileKotlin
and not top-level sourceSets)
compileKotlin {
dependsOn(delombok)
sourceSets.main {
java.setSrcDirs(listOf(“${project.buildDir}/generated/sources/delombok/java/main”))
}
}
Vampire
05/23/2021, 2:05 PMthis is strange as I only have set it up inNot really. Your code is withinand not top-level sourceSetscompileKotlin
compileKotlin
but actually that is just a code smell in your build script, as there is no sourceSets
property in the compileKotlin
task.
WHat you wrote is essentially the same as
sourceSets.main {
java.setSrcDirs(listOf("${project.buildDir}/generated/sources/delombok/java/main"))
}
compileKotlin {
dependsOn(delombok)
}
with the exception that is is only done when compileKotlin
is configured as you do it in the configuration phase of that task.
But actually using manual hard-coded paths and manual task dependencies is a pretty bad and non-idiomatic idea anyway. You should usually wire task in- and outputs instead and thus also get implicit task dependencies where needed automatically.
Unfortunately I cannot suggest how you properly should do it from your short example. Maybe if you can provide a proper MCVE.Gopal S Akshintala
05/23/2021, 2:43 PMGopal S Akshintala
05/23/2021, 3:02 PMGopal S Akshintala
05/23/2021, 3:05 PMkapt
is fixed and it can be used with lombok with 1.5.20-M1
kotlin. I did try that using below, but in vain!
compileOnly("org.projectlombok:lombok:1.18.20")
// annotationProcessor("org.projectlombok:lombok:1.18.20") // I tried this too
kapt("org.projectlombok:lombok:1.18.20")