Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override dependencies in a maven plugin (one plugin, different modules and different dependencies)

I have a java project which has more modules. In some of the modules I use a plugin. In that plugin I nee to override one from its dependencies. So far so good. Solved with adding of the desired dependency in the plugin definition.

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>xdoclet-maven-plugin</artifactId>
   <version>1.0</version>
   <dependencies>
      <dependency>
         <groupId>xdoclet</groupId>
         <artifactId>xjavadoc</artifactId>
         <version>1.5-SNAPSHOT</version>
       </dependency>
   </dependencies>
   ...

But in one of the modules I need to override that dependency with some other version. I tried to solve that with the same way as overriding. If I compile only that submodule alone, the correct dependency version is used, but if I compile whole project it does not work, because it uses the dependency from other modules for the plugin and not the one specified in the modules pom.

Any idea how to solve my problem?

Best regards, Filip

like image 974
NonSense Avatar asked Jul 02 '13 09:07

NonSense


People also ask

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.

What is the difference between plugins and dependencies in Maven?

A plugin is an extension to Maven, something used to produce your artifact (maven-jar-plugin for an example, is used to, you guess it, make a jar out of your compiled classes and resources). A dependency is a library that is needed by the application you are building, at compile and/or test and/or runtime time.


1 Answers

You can create property for your plugin version, e.g xdoclet.version and use it to override parent version.

<properites>
   <xdoclet.version>1.5-SNAPSHOT</xdoclet.version>
</properties>
...
<plugin>enter code here
<groupId>org.codehaus.mojo</groupId>
<artifactId>xdoclet-maven-plugin</artifactId>
<version>1.0</version>
<dependencies>
  <dependency>
     <groupId>xdoclet</groupId>
     <artifactId>xjavadoc</artifactId>
     <version>${xdoclet.version}</version>
   </dependency>
</dependencies>
...
like image 81
SanyaLuc Avatar answered Nov 15 '22 06:11

SanyaLuc