I have a project with a lot of Gradle modules in it. Sometimes a module or two gets deleted by other members of our team.
Since build
directories are added to gitignore they persist in my local files. For a lot of modules it gets annoying.
I tried gradle clean
, but it does not help there: deleted modules are not modules and Gradle doesn’t know about them or their build files.
To remove build files for deleted Gradle modules, follow these steps:
1. Remove the Module from Settings
Open your project’s settings.gradle (or settings.gradle.kts if using Kotlin DSL).
Remove the module entry for the deleted module, which will look like:
include ‘:module-name’
If you had the module listed in multiple places, ensure you remove all occurrences.
2. Clean the Project
Run the following command to remove any leftover build files:
bash
./gradlew clean
3. Manually Delete Leftover Build Files
Gradle’s clean task removes most build files, but you might still have residual files for deleted modules. Check the following:
Module Directory: If the physical directory of the deleted module still exists in your project, delete it manually:
Example: ./your-project/module-name/
Build Output: Check the build directory and remove any associated build artifacts:
Example: ./build/module-name/
4. Invalidate Caches (Optional)
If you’re using an IDE like Android Studio, you can invalidate caches and restart:
Go to File > Invalidate Caches / Restart > Invalidate and Restart.
This will ensure no residual files remain for the deleted module.
1