Right way to generate sources in Gradle 7

We treat javac warnings as errors, and the generated code contains such warnings, so we cannot add the sources to the main source set and have them compiled that way.

I found How to add generated sources to compile classpath without adding them to the main sourceSet? - #3 by Benjamin_Manes that tries to solve that problem, but in our context we also use dependency locking, and solving it the way that post suggests it highlighted a problem: the dependencies from the code generation configuration leaks out to the main classpath (without solving the problem, the classes are still not present in the war file).

In essence, I think we would want a separate source set for the generated code, build it in that source set, and then include the .class files in the resulting war file as classes. Or alternatively build a JAR out of the generated code, and include it that way.