Create New Module Programitically


I am working on a plugin and want to create a Kotlin module programmatically as we have in New Module Action.

override fun actionPerformed(event: AnActionEvent) {
val project = event.getData(PlatformDataKeys.PROJECT) ?: return

val dataContext = event.dataContext
val module = LangDataKeys.MODULE.getData(dataContext) ?: return

runWriteAction {

val moduleManager = ModuleManager.getInstance(project)

val newModule = ModuleManager.getInstance(project).newModule(
project.basePath + "/" + + ".abdul" + ModuleFileType.DOT_DEFAULT_EXTENSION,


So this creates a new Module that gets shown in settings but unable to see in the package. Also after that, I have to create different folders like src, main etc and then I have to add files.
Any idea how I can do that. 

Comment actions Permalink

Hi Abdul,

Please see:

Comment actions Permalink

Thanks, Karol Lewandowski got it. This is how I am doing it, Would love to hear your thoughts on this,

var f: VirtualFile = createProjectSubFile(
val module = ModuleManager.getInstance(project).newModule(f.path, ModuleTypeId.JAVA_MODULE)

val model = ModuleRootManager.getInstance(module).modifiableModel
val contentEntry: ContentEntry = model.addContentEntry(f.parent)
contentEntry.addSourceFolder(contentEntry.file?.url!!, false)


Please sign in to leave a comment.