In theory, you could implement this with Gradle's variants, but I don't advise it. I've been playing with them myself and they're very unstable when it comes to KMP.
What is the difference between both artifacts? You mention the release artifacts don't contain the implementation code, but that doesn't make sense to me, that code is required at runtime for the library to do anything?
If the difference is the presence of debug statements, you can have a global boolean to enable/disable debug mode, and hope that the runtime will inline it everywhere (at least, the JVM should).