I am using `id("io.freefair.lombok") version "6.0....
# gradle
g
I am using 
id("io.freefair.lombok") version "6.0.0-m2"
 plugin for lombok on gradle. I have a mix of Java and Kotlin. My plan is to delombok java code and use that while compiling kotlin code. I tried below, but Kotlin doesn’t pick-up delomboked classes. What am I missing?
Copy code
ourceSets.main {
    java.srcDirs("${project.buildDir}/generated/sources/delombok/java/main")
}

tasks {
    delombok {
        quiet.set(true)
    }
    compileKotlin {
        dependsOn(delombok)
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_11.toString()
        }
    }
}
n
you can add the directory where the delomboked code ends up in as kotlin srcDir, it probably triggers the task but does not use the generated sources since they are only added for java (iirc src/main/java is added by the kotlin plugin itself as a compatibility thing) if you are in kotlin multiplatform you need to configure it like so
Copy code
jvm { withJava() }
g
@Nikky but I did add the delombok directory as you can see from my code, do I need to add in any other way?
n
you add it to java.. try
Copy code
kotlin.sourceSets.main {
    kotlin.srcDir(buildDir.resolve("generated/sources/delombok/java/main"))
}
instead maybe ?
although i am not sure if this will make it eat the java input.. it worked for me to throw java files in the kotlin sources before
g
@Nikky Thanks alot… this worked… however one slight problem… how can I cleanup the delombok code that’s add to sourceSets? delombok in srouceSets is causing Intellij to showup red lines everywhere in actual source
n
Mark the folder as generated-src with the gradle idea plugin maybe?
g
oh hvnt done this before, will google around, thanks
Copy code
build {
        doLast {
            delete(buildDir.resolve("generated/sources/delombok/"))
        }
    }
Tried the above just now seems to be working as expected… but not sure if it’s right
@Nikky tried this, doesn’t seem to be working, did I get it right?
Copy code
idea {
    module.generatedSourceDirs.add(buildDir.resolve("generated/sources/delombok/java/main"))
}
I use
build.gradle.kts
n
Seems like it should work, does delombok produce invalid Java code or just lots of suggestion and warning from idea?
I wonder if you could configure idea to suppress warning in a folder..
g
no its treating it as duplicates
I get ambiguous method calls error
in the actual src
because now there are two methods in the same pkg, from from
src/main/java
and other from delombok generated sources
n
i would suggest to split it into a module with just java and delombok and have the kotlin module just use the delomboked code unless you can configure delombok to use input from some directory that is not used by the rest of the compilation.. but then you need to explicitely mark it as srcDir for idea to be happy.. and its a bit messy .. if it works at all
downside of submodules is that your lombok code cannot call kotlin code anymore