Exclude package from jar

Hello everyone!

I add classes from external jar files to my jar file:

from {
    	configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}

but for my task, I do not need all the added packages, but to be precise, I need to exclude one jar from the created one.
Or I need not to add it to my jar using this function:

from {
    	configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}

Does anyone know how to do this?
I tried various options for exclude, it does not work.
Tried sourceSet, also fails.
In all cases, an external jar file is added to the created one.
Thanks in advance!
Respectfully!

Tried exclude again
It seems to work.
but if anyone knows a solution better, I will be very grateful if you tell me it.