# Need help with understanding how to import Maven project on IntelliJ project open

**URL:** <https://platform.jetbrains.com/t/need-help-with-understanding-how-to-import-maven-project-on-intellij-project-open/2445>\
**Category:** IntelliJ Platform\
**Tags:** api, plugin-development\
**Created:** [August 5, 2025, 2:22pm UTC](https://platform.jetbrains.com/t/need-help-with-understanding-how-to-import-maven-project-on-intellij-project-open/2445 "2025-08-05T14:22:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![taleks](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@taleks](https://platform.jetbrains.com/u/taleks)\
**Post date:** [August 5, 2025, 2:22pm UTC](https://platform.jetbrains.com/t/need-help-with-understanding-how-to-import-maven-project-on-intellij-project-open/2445/1 "2025-08-05T14:22:08Z")

</div>

I am experimenting with plugin DevKit.

What I want to do:

- On IntelliJ project open check if folder contains configuration file with specific filename; if it does then read that file and import referenced Maven projects as external model modules.

What I did:

- got some directions from old topics and platform examples:
  - [https://intellij-support.jetbrains.com/hc/en-us/community/posts/18505236720914-How-to-mark-Modules-when-opening-a-project](https://intellij-support.jetbrains.com/hc/en-us/community/posts/18505236720914-How-to-mark-Modules-when-opening-a-project)
  - [https://intellij-support.jetbrains.com/hc/en-us/community/posts/4418146512658-Create-New-Module-Programitically](https://intellij-support.jetbrains.com/hc/en-us/community/posts/4418146512658-Create-New-Module-Programitically)

- registered `postStartupActivity`
- 

```xml
<extensions defaultExtensionNs="com.intellij">
    <postStartupActivity implementation="my.stuff.ProjectOpenStartupActivity"/>
</extensions>

```

- implemented `ProjectActivity` for the extension point

```kotlin
import com.intellij.ide.actions.ImportModuleAction

internal class ProjectOpenStartupActivity : ProjectActivity, DumbAware {

    override suspend fun execute(project: Project) {

        val configuredPaths: List<String> = readWellKnownConfig()

        val mavenProvider = ImportModuleAction.getProviders(null)
            .firstOrNull { it.name == "Maven" }

        writeAction {
            for (mavenProjectPath in configuredPaths) { // /path/to/package-one/pom.xml

                val pomFile = LocalFileSystem.getInstance()
                    .refreshAndFindFileByPath(mavenProjectPath) // file:///path/to/package-one/pom.xml

                if (!mavenProvider.canImport(pomFile, project)) {
                    continue
                }

                val wizard = ImportModuleAction.createImportWizard(project, null, pomFile, mavenProvider)!!

                ImportModuleAction.createFromWizard(project, wizard)
            }
        }
    }
}

```

What I observe:

- never ending progress bar, looks like importer got the intention but is blocked/waiting forever.

- No exceptions are reported

- if cancelled, the same project could be imported in a few seconds from UI (File → New → Module from existing sources → import module from external model

So question is: what could be amiss? And where should I look for any leads on what went wrong? Looks like waiting on (write?) lock, but if so then what is a proper way to invoke `ImportModuleAction?`

Any help is much appreciated.

General environment details:

```ini
platformType = IC
platformVersion = 2024.2.5
platformBundledPlugins = org.jetbrains.idea.maven, com.intellij.java, org.jetbrains.idea.maven.model, org.jetbrains.idea.maven.server.api

```

---

<div class="post-metadata">

**Author:** ![taleks](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@taleks](https://platform.jetbrains.com/u/taleks)\
**Post date:** [August 6, 2025, 11:35am UTC](https://platform.jetbrains.com/t/need-help-with-understanding-how-to-import-maven-project-on-intellij-project-open/2445/3 "2025-08-06T11:35:21Z")

</div>

I did a bit of brute-forcing different options and it started to work as expected (whether it is the right way of doing things or not… who knows):

```diff
@@ -9,7 +9,7 @@
         val mavenProvider = ImportModuleAction.getProviders(null)
             .firstOrNull { it.name == "Maven" }
 
- writeAction {
+ withContext(Dispatchers.Main) {
             for (mavenProjectPath in configuredPaths) { // /path/to/package-one/pom.xml
 
                 val pomFile = LocalFileSystem.getInstance()

```

Presumably `Dispatchers.EDT` should be available ([doc](https://plugins.jetbrains.com/docs/intellij/coroutine-dispatchers.html#ja09fz_58)) but for some reason it is not in IdeaIC.2024.2.5 so `Main` covers for it.
