Persist ModuleComponent in a user defined file?


my persistent ModuleComponent looks like:

    name = "moduleSettings",
    storages = {
        @Storage(id = "default", file = "$MODULE_FILE$") // btw. why is MODULE_FILE missing in StoragePathMacros ?
public class ModuleSettings implements PersistentStateComponent<Settings>, ModuleComponent { ... }

This way the settings are saved to $projectRoot$/my-project.iml, which is the intellij module configuration file.

Can I define the location of file manually like I can do it for ProjectComponent?

My ProjectComponent:

    name = "projectSettings",
    storages = {
        @Storage(id = "default", file = StoragePathMacros.PROJECT_FILE),
        @Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR + "/mySettings.xml", scheme = StorageScheme.DIRECTORY_BASED)
public class ProjectSettings extends AbstractProjectComponent implements PersistentStateComponent<Settings> { ... }

This way project settings are saved to $projectRoot$/.idea/mySettings.xml

If I add

@Storage(id = "dir", file = StoragePathMacros.PROJECT_CONFIG_DIR + "/mySettings.xml", scheme = StorageScheme.DIRECTORY_BASED)

to my moduleComponent, then the settings are not saved any more

Is there are way to force saving in a file defined manually?

Additionaly: what is the preffered way by design to persist project and module settings, in intellij files together with all other settings or in a self defined file ?
In long term I want make it possible to share the configuration by adding it to the version control system (git).

Thank you!
1 comment
Comment actions Permalink


no, it isn't possible to save module settings into a separate file, all the module configuration is saved in *.iml file.

It may be ok to persist project-level settings together with other settings in the default PROJECT_FILE (it's *.ipr file for file-based scheme and
.idea/misc.xml for directory-based scheme) if these settings don't take too much space in xml and don't change too often.

Nikolay Chashnikov
"Develop with pleasure!"


Please sign in to leave a comment.