Terasology
Terasology copied to clipboard
gracefully remove module subprojects from IntelliJ IDEA
What you were trying to do
Remove my local clone of some things under my modules/
workspace.
What actually happened
-
idea
gives errors the next time I start it - it re-creates the directories I just deleted in
modules/
- there's a bunch of clutter left behind in its list of git roots (entries in red pointing to things that no longer exist)
...
after a gradle re-sync you can delete the directories again and I believe it will leave them alone at that point, but the clutter in the list of version control roots is still there. (I don't know that it causes problems other than clutter in that one settings screen, though. as long as they don't show up in the other places you interact with git branches)
IntelliJ has two things going on here.
- the intellij-modules of this intellij-project. created and synchronized with gradle in our case.
- its list of git root directories
if intellij does a gradle-sync and finds a module gradle used to control is no longer part of the project, it handles this part fairly well. There's a little notice that says "hey, last sync removed these things, let me know if you need me to restore them."
but that gradle-sync happens only after it's loaded its own stored configuration about those modules, so there's a gap when it's not synchronized, and my hunch is that's when those directories get re-created.
As for the git stuff, it's been very nice for it to auto-detect them when they're created. It's just not very good at auto-cleaning.
potential ways to address this:
- some script that removes all the not-valid-module-subdirectories under
modules/
? so the ide will still flail, but at least cleaning up after it is easier - intellij plugin to do module management?
- report as bug to jetbrains? should do this, but I would not be surprised if a workflow that involves deleting subprojects on a regular basis is pretty rare and low-priority for them.
I am delete module's dir twice from IDEA. First - remove module Second - delete folder. Then press gradle reimport button. (I don't use auto-import)
I thought deleting from IntelliJ might help, instead of rm -rf
from the command line (also, I got burned by rm -rf-ing the wrong directory the other day), and I've just done as you described.
- in IntelliJ's Project view, choose "Project Files" view, highlight all directories under
modules/
- IntelliJ asks me if I want to delete all these modules, says no files will be deleted. I agree.
- the directories are still there, but no longer have IntelliJ's "module" icon on them
- I push delete again to delete all those directories.
- I reimport gradle
- directories come back! With just this in them:
$ ls -R Behaviors/build/
Behaviors/build/:
classes testClasses
Behaviors/build/classes:
generated META-INF
Behaviors/build/classes/generated:
Behaviors/build/classes/META-INF:
Terasology.modules.Behaviors.main.kotlin_module
Behaviors/build/testClasses:
generated_tests META-INF
Behaviors/build/testClasses/generated_tests:
Behaviors/build/testClasses/META-INF:
Terasology.modules.Behaviors.main.kotlin_module
so I'm not sure if this is an IntelliJ bug or a gradle bug, since it doesn't happen until the gradle re-import.
It's weird for those to have a kotlin_module
at all, since the only thing we have kotlin set up for is our /buildSrc
, which isn't this.
Those .kotlin_module
files only contain 16 bytes:
00 00 00 03 00 00 00 01 00 00 00 01 00 00 00 10
Oddly on Win10 here with IntelliJ 2020.1 I'm having no problems. Delete twice from inside IntelliJ and poof. Maybe sync Gradle just for funs. Nothing comes back.
Sometimes if I've had the game running IntelliJ won't actually let me finish deleting things as it thinks they're in use. Then I can delete via explorer and it goes poof. Worst case restart IntelliJ if I can't shake whatever file lock.
fix: go to .idea directory (root of the project) and find gradle.xml; then find that unused subproject section (<GradleProjectSettings> tag) and delete it; then just re-sync and delete the directory of subproject