Locating source jars for Module Dependencies

I need programmatic access to the source jars or source directories, for all the dependencies for a particular module.

((ApplicationConfiguration) configuration).getConfigurationModule().getModule().
getModuleWithDependenciesAndLibrariesScope(false);


I was able to get some form of access to jar files with the above, but not to the source jars.

I can hack it by using information from:
     <project location>/.idea/libraries
     <module>.iml

But I would prefer access the info using the APIs. Is there a way to do this?

2 comments
Comment actions Permalink

Of course, there is. ModuleRootManager.getInstance(module).orderEntries().recursively().sources().getRoots(). You can specify additional restrictions: for example, if you're only interested in dependent libraries and not the SDK or dependent modules, use orderEntries().librariesOnly(). For more details, see the OrderEnumerator class:

https://upsource.jetbrains.com/ideac/file/HEAD/platform%2FprojectModel-api%2Fsrc%2Fcom%2Fintellij%2Fopenapi%2Froots%2FOrderEnumerator.java

0
Comment actions Permalink

Thanks very much, works well.

0

Please sign in to leave a comment.