Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude dependency in a Maven plugin?

I have a project that needs the following Maven jibx plugin:

  <build>     <plugins>       <plugin>         <groupId>org.jibx</groupId>         <artifactId>maven-jibx-plugin</artifactId>         <version>1.2.2</version>         ...       </plugin>     </plugins>   </build> 

Inside the jibx plugin pom, there is a xpp3 dependency which I want to exclude from my project build process (due to some reason I cannot have it inside my private repository).

Is there a way to config my pom.xml (not the plugin pom) to exclude that dependency?

EDIT: I tried to remove the xpp3 dependency from the plugin pom and the project could be built successfully, so I know the dependency is not mandatory.

like image 404
Tommy Siu Avatar asked May 17 '11 09:05

Tommy Siu


People also ask

Can we exclude dependency from plugin?

We can exclude the dependencies that are not declared but used or the dependencies that are used but not declared using maven plugins.

How you can exclude dependency in Maven?

You can use Exclude command from the context menu in the Maven dependency diagram to quickly exclude the specified dependency from POM and the respective tool windows. The dependency is also excluded from the Project and Maven tool windows.

How do I make Maven dependency optional?

In order to exclude these special dependencies from the main project, we can apply Maven's <optional> tag to them. This forces any user who wants to use those dependencies to declare them explicitly. However, it does not force those dependencies into a project that doesn't need them.


1 Answers

Here is an example where the jetty-maven-plugin has a dependency on jtidy replaced with a newer version:

http://jira.codehaus.org/browse/JETTY-1339?focusedCommentId=257747&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#action_257747

    <plugin>         <groupId>org.mortbay.jetty</groupId>         <artifactId>jetty-maven-plugin</artifactId>         <dependencies>           <dependency>             <groupId>net.sf.jtidy</groupId>             <artifactId>jtidy</artifactId>             <version>r938</version>           </dependency>           <dependency>             <groupId>org.apache.maven.plugin-tools</groupId>             <artifactId>maven-plugin-tools-api</artifactId>             <version>2.5.1</version>             <exclusions>               <exclusion>                 <groupId>jetty</groupId>                 <artifactId>jetty</artifactId>               </exclusion>             </exclusions>           </dependency>         </dependencies> [...]       </plugin> 
like image 168
Nathan Feger Avatar answered Sep 23 '22 01:09

Nathan Feger