Adding a directory path under IntelliJ 12 claims Library 'LibraryName' is not used and has no effect

Hi,
we created a relatively simple plugin for Codename One support. It effectively just hides our ant build system.
However, when we try to change the classpath we get the error message: "Library 'x' not used"

And as a result we can't get code completion or anything else to work. I posted the question on SO http://stackoverflow.com/questions/21626113/adding-a-directory-path-under-intellij-12-claims-library-libraryname-is-not-us as well.

I'm somewhat at loss on why this is happening and where I should start looking?

Thanks.

6 comments
Comment actions Permalink

Hello,

it is not enough to create a project library, you also need to add it to the dependencies list of a module ('Dependencies' tab of the module editor).

--
Nikolay Chashnikov
JetBrains
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

Thanks. Please forgive my ignorance here but where is the module editor?
Is it possible our plugin inadvertantly disabled it?

This is my module settings UI



Attachment(s):
Screen Shot 2014-02-10 at 14.03.57.png
0
Comment actions Permalink

FYI some additional info, I got some help on StackOverflow and it seems our plugin doesn't handle the modules section correctly. This isn't necessarily bad since we don't want developers changing the classpath, but I want to be able to define the dependencies correctly for the project I generate. How do I do that?

Thanks.



Attachment(s):
Screen Shot 2014-02-11 at 18.01.33.png
0
Comment actions Permalink

'Dependencies' tab is shown only for Java modules by default, it won't be shown if your module has a custom ModuleType.

To add a dependency to a module via API use ModuleRootManager class:

ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
model.addLibraryEntry(library);
model.commit();

--
Nikolay Chashnikov
JetBrains
http://www.jetbrains.com
"Develop with pleasure!"

0
Comment actions Permalink

OK I just tried this is the code I have for project creation, I ran in the debugger and it seems this code is executing properly but the result is exactly the same as above:
    @Override
    void createProjectFolders(VirtualFile rootPath) throws IOException {
        super.createProjectFolders(rootPath);
        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.cn1lib.name";
                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);
                    model.commit();
                    ModifiableRootModel rmodel = com.intellij.openapi.roots.ModuleRootManager.getInstance(getModule()).getModifiableModel();
                    rmodel.addLibraryEntry(library);
                    rmodel.commit();
                }
                result.setResult(library);
            }
        }.execute();
    }

0

Please sign in to leave a comment.