void () { final VirtualFile dir = createFile("dir/a.txt").getParent(); final VirtualFile dir2 = createFile("dir2/b.txt").getParent(); final Artifact artifact = addArtifact(root().dirCopy(dir)); renameFile(dir, "xxx"); assertLayout(artifact, "<root>\n" + " dir:" + getProjectBasePath() + "/xxx"); final PackagingElementFactory packagingElementFactory = PackagingElementFactory.getInstance(); ModifiableArtifactModel model = ArtifactManager.getInstance(myProject).createModifiableModel(); ModifiableArtifact mutableArtifact = model.getOrCreateModifiableArtifact(artifact); mutableArtifact.getRootElement().addFirstChild(packagingElementFactory.createDirectoryCopyWithParentDirectories(dir2.getPath(), "/")); WriteAction.run(() -> { model.commit(); }); assertLayout(artifact, "<root>\n" + " dir:" + getProjectBasePath() + "/dir2\n" + " dir:" + getProjectBasePath() + "/xxx" ); renameFile(dir2, "yyy"); assertLayout(artifact, "<root>\n" + " dir:" + getProjectBasePath() + "/yyy\n" + " dir:" + getProjectBasePath() + "/xxx" ); }