Advice on updating Ivy plugin to handle libraries like Maven plugin

The IvyIDEA and Maven plugins add dependency libraries quite differently. Further, the Maven dependencies properly show up in IntelliJ WAR Artifacts. So I've got the source for IvyIDEA, and I've gotten and built the Community Edition with the Maven plugin, and its source etc. I intend to make the Ivy plugin deal with libraries the same way that Maven does, but there's a lot to get my head around. Any pointers to documentaiton or advice would be much appreciated.

To go into a bit more detail, the IvyIDEA plugin adds an OrderEntry type "module-library" which contains a single library with

    <orderEntry type="module-library">
      <library name="IvyIDEA">
          <root url="jar://$USER_HOME$/.ivy2/cache/commons-lang/commons-lang/jars/commons-lang-2.4.jar!/" />
          <root url="jar://$USER_HOME$/.ivy2/cache/org.hibernate/hibernate/jars/!/" />
          <root url="jar://$USER_HOME$/.ivy2/cache/org.hibernate/hibernate-annotations/jars/!/" />

Whereas the Maven plugin creates a Project library for every dependency and then references those in the project:

    <orderEntry type="library" name="Maven: org.springframework:spring-beans:3.1.1.RELEASE" level="project" />
    <orderEntry type="library" name="Maven: org.springframework:spring-core:3.1.1.RELEASE" level="project" />
    <orderEntry type="library" name="Maven: org.springframework:spring-asm:3.1.1.RELEASE" level="project" />

There are a couple of advantages to this:

1. There's only one set of data per project, so if I manually attach sources in one module, it applies to all.
2. WARs get the libraries. Don't know why they don't with Ivy, but there you go.

So that's my goal. Thanks for reading.
1 comment
Comment actions Permalink

You can use the following methods:
1) LibraryTablesRegistrar.getInstance().getLibraryTable(project).createLibrary(name)
to create a project level library;
2) model = library.getModifiableModel(); model.addRoot(...); model.commit();
to add classes/sources roots to the library
3) model = ModuleRootManager.getInstance(module).getModifiableModel(); model.addLibraryEntry(library); model.commit();
to add the library to a module dependencies list.

Nikolay Chashnikov
Software Developer
JetBrains, Inc
"Develop with pleasure!"


Please sign in to leave a comment.