Excluding transitive dependency in a Maven project from an IDEA plugin


Our plugin analyses and shows security and licenses issues in Maven projects.
In it, we display the project's components-tree (direct and transitive) with the corresponding known issues.

We would like to add a functionality, in which a user can right-click a component, and exclude it from the maven project.
To do so, we have the selected GroupId, ArtifactId and version of the component, and the MavenProject (provided by the MavenProjectsManager).

After using your guide for excluding components via the dependencies-graph UI, I was wondering if there is an API I can use to achieve this programmatically from our plugin.

Your help is highly appreciated.

Comment actions Permalink

Not clear what API do you need. I see you are aware of MavenProjectsManager.

If I understood correctly, I think you have to change pom.xml file programmatically, and add <exclusions> tag, then reimport project (using MavenProjectsManager#scheduleImportAndResolve())

You can consider org.jetbrains.idea.maven.dom.model.MavenDomExclusions (see https://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview/psi.html - how to work with PSI

and https://www.jetbrains.org/intellij/sdk/docs/reference_guide/frameworks_and_external_apis/xml_dom_api.html - XML API

), to work with PSI of pom.xml files.


Comment actions Permalink

Thanks Alexander Bubenchikov, I ended up using the XML API you suggested.

Upon changing the pom.xml file (using WriteCommandAction) the Maven Plugin starts a refresh, and we are using an implementation of MavenProjectsTree.Listener to refresh our plugin's components.

Thanks for your help.


Please sign in to leave a comment.