Can I remove classes from a jar file?

I’m using a library that is being a bad netizen and it is including a bunch of classes for another path (in this case com.kotlin).

If this library was including them as dependencies, I could simply do

testImplementation(library) {
  exclude(group = "com.kotlin")
}

However, it is not the case. They are just included in the jar file. How can I remove those files from the jar file, or at least instruct Gradle not to include them in the classpath?

That’s by far not trivial.
But the best method would probably be an artifact transform that carves out those files from that jar and leaves all other artifacts untouched.