Is it possible to get SourceSets without dependenc...
# plugin-development
c
Is it possible to get SourceSets without dependencies? For example, we're writing a code formatter/validator. We don't want sources that were registered with i.e. a code-generation framework (grpc/graphql/jooq/openapi) to be included as an input, nor do we want these task to be run if we're just checking format. Most formatting plugins I've seen end up depending on code-generation tasks, and I'm wondering if there's ways to avoid that
v
If all parties play nicely, that is exactly the expected behavior. 🙂 Code generation tasks should be wired properly as source directories so that whoever needs to operate on sources has the task dependency and also gets the generated sources, be it a sources jar task, a compilation task, some static code analyzer task (which also might need those sources to properly work, for example to determine null-ness, ...). And source consuming tasks should use all configured sources, thereby getting also the necessary task dependencies and all generated sources. The usual way to differentiate there is, to make sure the generated classes have a certain annotation like
@Generated
that is visible to the consuming tool (if it has source retention and a tool operates on the bytecode this would not work for example). JaCoCo for example automatically excludes any code with an annotation with simple name
Generated
by default iirc. So all tools that generate code should optimally mark it accordingly, and all tools that care about whether to operate on generated code should support some way to configure exclusions based on annotations. For a code formatter/validator even a source-retention annotation like
javax.annotation.Generated
or
javax.annotation.processing.Generated
should be enough as it is operating on the sources anyway.
I'm not aware of any clean way to tell "give me only the sources that are not outputs of some task"
c
@Vampire always appreciate your insight into these things.
❤️ 1