JetBrains/intellij-community · error · ConfigurationException
module.paths.validation.duplicate.content.error
module.paths.validation.duplicate.content.error
Error message
Content root ''{0}'' is defined for modules ''{1}'' and ''{2}''.
Two modules in a project cannot share the same content root. What it means
Thrown by ModulesConfigurator when the exact same content root directory is assigned to two different modules (contentRootToModuleNameMap.put returns the previous, different module name). Two modules cannot share a content root — both would claim the same files for indexing, VCS and compilation — so the model update is rejected.
Source
Thrown at java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/ModulesConfigurator.java:307
if (!sourceRoots.add(root)) {
throw new ConfigurationException(
JavaUiBundle.message("module.paths.validation.duplicate.source.root.in.same.module.error", root.getPresentableUrl(),
moduleName));
}
}
}
// Check for duplicate content roots across modules and map source roots to content roots
for (ContentEntry contentEntry : contents) {
final VirtualFile contentRoot = contentEntry.getFile();
if (contentRoot == null) {
continue;
}
// Check for duplicate content roots
final String previousName = contentRootToModuleNameMap.put(contentRoot, moduleName);
if (previousName != null && !previousName.equals(moduleName)) {
throw new ConfigurationException(
JavaUiBundle.message("module.paths.validation.duplicate.content.error", contentRoot.getPresentableUrl(), previousName, moduleName)
);
}
// Map source roots to content roots and check for duplicates
for (VirtualFile srcRoot : contentEntry.getSourceFolderFiles()) {
final VirtualFile anotherContentRoot = srcRootsToContentRootMap.put(srcRoot, contentRoot);
if (anotherContentRoot != null) {
throwDuplicateSourceRootError(srcRoot, contentRoot, anotherContentRoot, contentRootToModuleNameMap);
}
}
}
}
/**
* Throws an appropriate error for duplicate source roots.
*/
private static void throwDuplicateSourceRootError(@NotNull VirtualFile srcRoot,View on GitHub (pinned to be881553f2)
Solutions
- In Project Structure > Modules, remove the content root from one of the two modules named in the message
- If the module is a duplicate import, delete the redundant module entirely
- Fix the .iml files: ensure each <content url="..."> appears in exactly one module
- For multi-project setups sharing sources, use one module with multiple source roots instead of two modules sharing one root
Example fix
<!-- before: two modules both declare content root $PROJECT_DIR$/shared --> <!-- module-a.iml --> <content url="file://$PROJECT_DIR$/shared"/> <!-- module-b.iml --> <content url="file://$PROJECT_DIR$/shared"/> <!-- after: only module-a owns it --> <!-- module-a.iml --> <content url="file://$PROJECT_DIR$/shared"/> <!-- module-b.iml --> <content url="file://$PROJECT_DIR$/b-own-root"/>
Defensive patterns
Strategy: validation
Validate before calling
Map<VirtualFile, String> owner = new HashMap<>();
for (Module m : ModuleManager.getInstance(project).getModules()) {
for (ContentEntry c : ModuleRootManager.getInstance(m).getContentEntries()) {
VirtualFile root = c.getFile();
if (root != null && owner.put(root, m.getName()) != null) {
// two modules share this content root: remove it from one before apply
}
}
} Try / catch
try {
configurator.apply();
} catch (ConfigurationException e) {
// message names both modules; drop the content root from the redundant one and retry
} Prevention
- Never copy a <content url="..."> block from one .iml to another
- Import shared sources once; use a single module with multiple source roots instead
- Run a periodic check that content root urls are unique across modules
When it happens
Trigger: Applying Project Structure changes where module A and module B each list the same directory as a content root; happens when the configurator validates editors in order and the second module's put() collides with the first's map entry.
Common situations: Importing two Maven/Gradle projects that both claim a shared parent directory; hand-edited .iml files copy-pasting a content url; splitting a module but forgetting to remove the old content entry; duplicate module import (same sources imported twice).
Related errors
- module.paths.validation.duplicate.source.root.in.same.module.error
- Module '{0}' already exist in project. Please, specify anoth
- module.paths.validation.duplicate.source.root.error
- Module {name} has no content roots and will not be created.
- Enter module file location
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/fe1ed78d6aee49db.
Report an issue: GitHub.