Validate a public api with annotation in multiple jars

I would like to compare the differences between 2 versions of a java api and break the build if they differ.

The problem is that the “public api” is in 3 jars. Some of the classes in each jar are annotated with @publicapi (the rest I want to ignore). Once I have the “public api” classes I want to run a tool like “clirr” on it to find the differences. Any ideas how I could achieve this?

I was thinking along the lines of declaring my 3 jars as dependencies, running an annotation processor on the classes in the jars to find the “public” classes, then either building a new “public api jar” or create a sourceset to sent into “clirr”.

Any ideas or alternative solutions?