Using ModifiableRootModel.addLibraryEntry still doesn't set the library dependency correctly

I appologize if its wrong to open a separate issue but I marked the previous one as answered:

Turns out it was too soon, even though I added this call the behavior is exactly the same as if the dependency is undefined. This is what I'm doing:
    void createProjectFolders(VirtualFile rootPath) throws IOException {
        final VirtualFile libImplClasses = ProjectPaths.findOrCreateChildDirectory(rootPath, "lib/impl/cls");
        final VirtualFile libImplStubs = ProjectPaths.findOrCreateChildDirectory(rootPath, "lib/impl/stubs");
        new WriteAction<Library>() {
            protected void run(final Result<Library> result) throws IOException {
                final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(getProject());
                String libName = "";
                Library library = libraryTable.getLibraryByName(MessageBundle.message(libName));
                if (library == null) {
                    library = libraryTable.createLibrary(libName);
                    final Library.ModifiableModel model = library.getModifiableModel();
                    model.addRoot(libImplClasses, OrderRootType.CLASSES);
                    model.addRoot(libImplStubs, OrderRootType.SOURCES);
                     ModifiableRootModel rmodel =  com.intellij.openapi.roots.ModuleRootManager.getInstance(getModule()).getModifiableModel();


Comment actions Permalink

When 'createProjectFolders' method is called? If it's called from an implementation of ModuleBuilder#setupRootModel method (or similar method taking
ModifiableRootModel as a parameter) you need to use the provided ModifiableRootModel instance instead of calling ModuleRootManager#getModifiableModel
otherwise your changes will be overwritten when the original ModifiableRootModel is committed. Also you don't need to commit the provided model
instance yourself.

Nikolay Chashnikov
"Develop with pleasure!"

Comment actions Permalink

Thanks again! That finally did it!


Please sign in to leave a comment.