Skip to content

Instantly share code, notes, and snippets.

@dkandalov
Created January 30, 2013 00:39
Show Gist options
  • Select an option

  • Save dkandalov/4669528 to your computer and use it in GitHub Desktop.

Select an option

Save dkandalov/4669528 to your computer and use it in GitHub Desktop.
adding jars to idea project
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