I'm not sure it's possible for these to go out of sync without the compilation breaking but perhaps there is an elegant way to verify 1:1 the consistency of gradle configuration declarations and the module's actual content.
I believe the simplest way would be to collect metadata about the configurations we know on the gradle side during compilation (moduleApi, moduleImplementation...) - then we can read such metadata in, say, distribution tests and verify if it's consistent with the module's declaration. This metadata can even be embedded inside the module itself (META-INF/gradle/metadata.properties or inside the manifest, as a separate section).
Migrated from LUCENE-10324 by Dawid Weiss (@dweiss)
Parent: #11291