How can I find the path to a file inside a plugin JAR?

I’ve shipped some common build logic inside a custom plugin. Inside my plugin, I “apply from” the common.gradle file so that its logic is available to all build scripts that use the custom plugin. Now, inside common.gradle I configure Checkstyle with a custom rules XML. Here is the tricky part that I can’t get around - how do I get the path to the XML file inside the plugin JAR?

Inside comm.gradle I’ve tried using buildscript.sourceFile, and then using a relative path to that as the common.gradle source file is in the JAR alongside the XML file. But when my plugin is used in a build script, calls to buildscript.sourceFile in common.gradle return null.

I’ve also tried searching the buildscript classpath inside common.gradle, and once I find my plugin I can get its path. But it seems that the buildscript classpath is also empty in common.gradle (of course, its not emptry in the build script that is using my plugin).

So now I’m stumped. How can I get the path to my XML file that is inside my plugin JAR, inside common.gradle? It seems that no matter what logic I use, it fails as the common.gradle file is being “applied from” from the main build script, and this seems to nullify a lot of variables inside common.gradle!