How do I change only the URL entry for a library added as a dependency to a module
Hi,
I need to update an existing library entry that has been added to a module. I obtain the Library using the LibraryTable from the ModifiableRootModel for the module:
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();library.getModifiableModel().getUrls(OrderRootType.CLASSES)[0]
To make the change I delete the library entry from the libraryTable and then create it again:libraryTable.removeLibrary(library);libraryTable.createLibrary("libName");
The problem I am facing with this approach is that the library order and the selection of the library being exported (under module settings -> dependecies) are not retained. The new lib is added at the end of the module dependencies.
Is there a way I can keep these configurations (lib order and export) unchanged or access them and add them to the new library while creating it ?
You can find the exact usage here.
Thanks,
Prateek
Please sign in to leave a comment.
Why don't you use Library.ModifiableModel.removeRoot() to remove the old class URL and then .addRoot() to add the new one?
Thanks, that did the trick. I somehow missed that API.
For any future reference, I used: