Hi Gradlers, Disclaimer: This is a gradle specific...
# gradle
g
Hi Gradlers, Disclaimer: This is a gradle specific and not specific to lombok or Kotlin.This works with Maven but I am struggling how to achieve the same with Gradle (with my half-knowledge). How can I selectively provide sourceSets for lombok with
src/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)
Copy code
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)
Copy code
compileKotlin {
        dependsOn(delombok)
        sourceSets.main {
            java.setSrcDirs(listOf(“${project.buildDir}/generated/sources/delombok/java/main”))
        }
    }
v
this is strange as I only have set it up in
compileKotlin
and not top-level sourceSets
Not really. Your code is within
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
Copy code
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.
g
Thanks a lot @Vampire for a detailed reply. I will send out my repo link in a while as I get to my lappy
@Vampire here is my git repo for better understanding of the context. Please suggest me a better and importantly and idiomatic way to achieve this. Thanks alot 🙂 https://github.com/overfullstack/vader
@Vampire Also I saw from this issue: https://youtrack.jetbrains.com/issue/KT-7112 that
kapt
is fixed and it can be used with lombok with
1.5.20-M1
kotlin. I did try that using below, but in vain!
Copy code
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")