Created
January 30, 2013 00:39
-
-
Save dkandalov/4669528 to your computer and use it in GitHub Desktop.
adding jars to idea project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.intellij.openapi.actionSystem.AnActionEvent | |
| import com.intellij.openapi.module.ModuleManager | |
| import com.intellij.openapi.roots.DependencyScope | |
| import com.intellij.openapi.roots.ModuleRootManager | |
| import com.intellij.openapi.roots.OrderRootType | |
| import com.intellij.openapi.roots.ProjectRootManager | |
| import ru.intellijeval.PluginUtil | |
| import static ru.intellijeval.PluginUtil.runWriteAction | |
| import static ru.intellijeval.PluginUtil.show | |
| import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable | |
| def sdk = ProjectRootManager.getInstance(event.project).projectSdk | |
| show(sdk.homePath) | |
| if (true) return | |
| show(com.intellij.util.PathUtil.getJarPathForClass(PluginUtil.class)) | |
| if (true) return | |
| runWriteAction { | |
| def moduleManager = ModuleManager.getInstance(event.project) | |
| def module = moduleManager.modules.first() | |
| def moduleRootManager = ModuleRootManager.getInstance(module).modifiableModel | |
| def libTable = moduleRootManager.moduleLibraryTable | |
| def library = libTable.createLibrary("ooo") | |
| library.modifiableModel.with { | |
| addJarDirectory( | |
| "file:///path/to/classes/", | |
| true, | |
| OrderRootType.CLASSES | |
| ) | |
| commit() | |
| } | |
| moduleRootManager.findLibraryOrderEntry(library)?.scope = DependencyScope.PROVIDED | |
| moduleRootManager.commit() | |
| show(library) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment