Gábor Török
07/29/2024, 11:30 PMsourceSet for our generated code.
i am working on a kotlin plugin for our build - the goal is that each project that has generated code should produce a single jar that contains all the generated and non-generated files.
I was able to achieve this:
val mainSourceSet = extensions.getByType<SourceSetContainer>().named("main").get()
val generatedSourceSet: SourceSet = extensions.getByType<SourceSetContainer>().create("generated") {
it.java.srcDir(outputDir)
it.compileClasspath += mainSourceSet.compileClasspath
}
mainSourceSet.apply {
compileClasspath += generatedSourceSet.output
}
tasks.named<Jar>("jar") {
from( generatedSourceSet.output )
}
with this, all the expected classes show up in the jar
however the problem is that in builds that include this build, we get a compilation error when we refer to any of the generated classes - and i can't figure out what's going wrong.ephemient
07/30/2024, 6:14 AMephemient
07/30/2024, 6:18 AMsourceSets.named("main") { java.srcDir(generated) }
then everything would work without other manipulationVampire
07/30/2024, 12:11 PMgenerated being the task that generates the code and has its outputs configured properly, so that also all source consumers automatically have the necessary task dependencies.ysb33r
07/30/2024, 2:45 PMephemient
07/30/2024, 4:30 PMsrcDirs which will set up the dependencies for anything that consumes them including JavaCompileysb33r
07/30/2024, 4:31 PMVampire
07/30/2024, 5:04 PMdependsOn where the left-hand side is not a lifecycle task is a code smell that usually means you are not wiring outputs and inputs together properly. 🙂Gábor Török
07/30/2024, 5:40 PMmain source set, and while most things worked fine, that has some issues: code checks, like spotbugs had to be disabled, because they consistently fail on the generated code.
that is not great, if we have both generated and non-generated code in the project.
the idea with creating a separate source set for the generated code is that we can just blanket disable code checks for that source set, and that seems to be simpler than setting up exclusion configuration.Vampire
07/30/2024, 5:51 PMephemient
07/30/2024, 5:55 PMVampire
07/30/2024, 5:56 PMephemient
07/30/2024, 5:57 PMVampire
07/30/2024, 5:58 PMVampire
07/30/2024, 5:59 PMGenerated, but afair also needs higher than source retention, but an own annotation is quickly written and added if needed, I did that in the past.Gábor Török
07/30/2024, 6:25 PMspotbugs can ignore based on the annotations, but only if there is an exclude filter xml configured for it, which is not convenient to create for every project (we are looking at potentially 20+ projects with some amount of generated code like this)ephemient
07/30/2024, 6:27 PMGábor Török
07/30/2024, 6:40 PMexcludeFilter - but that requires an extra xml in every project.ephemient
07/30/2024, 6:40 PMspotbugs {
excludeFilter = rootProject.file("spotbugs-exclude.xml")Gábor Török
07/30/2024, 6:43 PM