As @Slaw stated in comments, I can use AbstractCopyTask#exclude. I don't know how I broke that before, but it works now with the following code:
jar.exclude((fileTreeElem) -> {
File theFile = fileTreeElem.getFile();
if (theFile.getPath().startsWith(customDir.getPath()))
return false;
// ... rest of the code
}