This works. Seems a little ugly to me as it must traverse multiple times and it very may well fail on multiple layers of symlinks
private void purgeDirectoryChildrenContainingSymlinks(File directoryToPurge) {
// Walk and Find all Symlinks
def pathsToPurge = []
directoryToPurge.eachFileRecurse { child ->
Path childPath = Paths.get(child.absolutePath)
if (Files.isSymbolicLink(childPath)) {
pathsToPurge << childPath
}
}
// Purge all Symlinks
pathsToPurge.each { child ->
Files.deleteIfExists(child)
}
// Walk and Purge remaining file structure
directoryToPurge.eachFile { child ->
project.delete(project.file(child.absolutePath))
}
}