Fix too aggressive cleanup of dependencies.
Merge pull request #3495 from ktf/fix-aggressive-cleanup

Fix too aggressive cleanup of dependencies.