I am banging my head on what is seemingly a normal use-case, but find 
myself stuck and need to ask for advice.  In essence, within a Gradle 
build, I am trying to use a code-generator (openapi-generator) to create 
some code, but have that code ignored by Jacoco.  I have been studying the 
solutions proposed, but they seem to go around in a circle, and I cannot 
successfully break out.

The openapi-generator applies either javax.annotation.Generated or 
jakarta.annotation.Generated (possibly a few other alternatives), but all 
of these have Retention = SOURCE.  I have been unsuccessful in figuring out 
how to get openapi-generator to apply a custom annotation. There is an 
issue here proposing that change:  
https://github.com/OpenAPITools/openapi-generator/issues/9752.   If the 
Jacoco maintainers feel strongly that a different @Generated should be 
allowed by code-gens, could you please comment thereupon.

In the Jacoco space, two options exist to ignore code.  The 'easy' answer 
is to apply a @Generated with RETENTION=(CLASS or RUNTIME), but (as above) 
that's not how the standard javax and jakarta annotations are configured. 
 As the specifications behind those implementations are already final, it 
is likely a large lift to get that changed therein.  It does not seem 
likely that javax.annotation.Generated (or jakarta) is likely to change.

The second option in Jacoco space is to use the 'afterEvaluate' hack (e.g. 
https://www.baeldung.com/jacoco-report-exclude#2-gradle-configuration).  As 
discussed in threads that led to the discovery of this approach (e.g. 
https://stackoverflow.com/questions/29887805/filter-jacoco-coverage-reports-with-gradle),
 
this is thought to be the only way to get jacoco to ignore classes (which 
might still be regarded as a bug in jacoco, idk).   Nevertheless, this does 
not work for generated code because 'afterEvaluate' is called prior to the 
code being generated - the classes do not yet exist, and they cannot be 
removed (yet).   If there is a different way to make Jacoco ignore 
(generated-code) based on package (or class) name, I have not figured out 
how to do so.

Intuitively, I should be able to set "excludes = ['**/generated/**/*']" in 
my jacoco Rule, but this does not work.

-- 
You received this message because you are subscribed to the Google Groups 
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jacoco+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/2246f07f-3fd1-4720-808b-cbdfc9826c83n%40googlegroups.com.

Reply via email to