cursive icon indicating copy to clipboard operation
cursive copied to clipboard

Issues when import monorepos with Deps

Open boschi opened this issue 2 years ago • 2 comments

There is an issue when importing a new project with existing sources, Deps style, you have a monorepo or something that might end-up having modules with the same name, for example the structure:

my-project

  • subproject-1
    • api
      • deps.edn
    • impl
      • deps.edn
  • subproject-2
    • api
      • deps.edn
    • impl
      • deps.edn
  • deps.edn

It throws an exception similar to this:

2022-12-07 22:43:33,891 [  28062] SEVERE - #c.i.i.p.PluginManager - Module already exists: api
com.intellij.openapi.module.ModuleWithNameAlreadyExists: Module already exists: api
	at com.intellij.workspaceModel.ide.impl.legacyBridge.module.ModifiableModuleModelBridgeImpl.newModule(ModifiableModuleModelBridgeImpl.kt:83)
	at com.intellij.openapi.externalSystem.service.project.AbstractIdeModifiableModelsProvider.newModule(AbstractIdeModifiableModelsProvider.java:113)
	at com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl.newModule(IdeModifiableModelsProviderImpl.java:117)
	at cursive.deps.project.DepsProjectImportBuilder.createTemporaryModule(ImportProject.kt:376)
	at cursive.deps.project.DepsProjectImportBuilder.commit(ImportProject.kt:355)
	at com.intellij.projectImport.ProjectImportBuilder.commit(ProjectImportBuilder.java:51)
	at com.intellij.ide.impl.NewProjectUtil.doCreate(NewProjectUtil.java:185)
	at com.intellij.ide.impl.NewProjectUtil.createFromWizard(NewProjectUtil.java:92)
	at com.intellij.ide.impl.NewProjectUtil.createFromWizard(NewProjectUtil.java:87)
	at com.intellij.ide.actions.ImportModuleActionKt.doCreateFromWizard(ImportModuleAction.kt:180)
	at com.intellij.ide.actions.ImportModuleActionKt.access$doCreateFromWizard(ImportModuleAction.kt:1)
	at com.intellij.ide.actions.ImportModuleAction$Companion.createFromWizard(ImportModuleAction.kt:47)
	at com.intellij.ide.actions.ImportModuleAction$Companion.doImport(ImportModuleAction.kt:41)
	at com.intellij.ide.actions.ImportProjectAction.actionPerformed(ImportProjectAction.java:13)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.doPerformActionOrShowPopup(ActionUtil.java:323)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.lambda$performActionDumbAwareWithCallbacks$4(ActionUtil.java:302)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.java:346)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAwareWithCallbacks(ActionUtil.java:302)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$performAction$5(ActionMenuItem.java:296)
	at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:226)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.performAction(ActionMenuItem.java:289)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$new$0(ActionMenuItem.java:64)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.lambda$fireActionPerformed$4(ActionMenuItem.java:111)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
	at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:94)
	at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:111)
	at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:526)
	at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:558)
	at java.desktop/java.awt.Component.processMouseEvent(Component.java:6648)
	at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3392)
	at java.desktop/java.awt.Component.processEvent(Component.java:6413)
	at java.desktop/java.awt.Container.processEvent(Container.java:2266)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5022)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4854)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2802)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4854)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:781)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:730)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:724)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:754)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:752)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:751)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:909)
	at com.intellij.ide.IdeEventQueue.dispatchMouseEvent(IdeEventQueue.java:831)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:753)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$5(IdeEventQueue.java:437)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:774)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:436)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:113)
	at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:615)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:434)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:813)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:480)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
2022-12-07 22:43:33,893 [  28064] SEVERE - #c.i.i.p.PluginManager - IntelliJ IDEA 2022.3  Build #IC-223.7571.182
2022-12-07 22:43:33,893 [  28064] SEVERE - #c.i.i.p.PluginManager - JDK: 17.0.5; VM: OpenJDK 64-Bit Server VM; Vendor: JetBrains s.r.o.
2022-12-07 22:43:33,893 [  28064] SEVERE - #c.i.i.p.PluginManager - OS: Linux
2022-12-07 22:43:33,893 [  28064] SEVERE - #c.i.i.p.PluginManager - Plugin to blame: Cursive version: 1.12.5-2022.3

boschi avatar Dec 08 '22 01:12 boschi

A manual workaround is to select to add just one of the sub-projects, then go to "Project Structure" -> "Modules", rename the modules "api" to "subproject-1-api" and similarly for the "impl" module, apply changes, then go to "CLojure Deps" tab and add the deps.edn files for the other sub-project. After that, rename manually the new modules, then go ahead with the other subprojects, and so on...

Yes, annoying....

boschi avatar Dec 08 '22 02:12 boschi

I've recently run into something I think is related to this with my (first!) monorepo.

I imported a module with the same directory name as a previous module (even though I'd changed the older module's name via Project Structure). That caused some weirdness where the older module disappeared from Project Structure and appeared to get overwritten by the newer module. (I also got a crash when I did that initial "Module from existing sources" import which I submitted via IntelliJ.)

After getting the IML files sorted with proper display names set, I noticed that the Clojure Deps view was still showing a single "service" module and triggering the overwriting behavior. I removed the "service" deps project and manually added both modules back. This time, Cursive picked up the proper module display names, and everything seems fine for now.

My guess is there is an assumption somewhere baked into module naming defaults.

Sorry for the vague issue report. I feel like I've bounced off this issue before, but this is the first time I ran it down (instead of just renaming the directory for the new module).

jdhollis avatar Jun 12 '23 19:06 jdhollis