1

I've see you can add dependencies element of the plugin element in a pom.

Question: What's for? Should'nt all the lib used by a plugin be include inside it? Do it surcharge some lib used by the plugin?

<plugin>
    <groupId>org.raml.plugins</groupId>
    <artifactId>raml-jaxrs-maven-plugin</artifactId>
    <version>1.3.4</version>
    <dependencies>
        <dependency>
            <groupId>org.raml</groupId>
            <artifactId>raml-parser-2</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
</plugin>
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
sab
  • 4,352
  • 7
  • 36
  • 60

2 Answers2

1

From official Maven POM Reference documentation:

dependencies: Dependencies are seen a lot within the POM, and are an element under all plugins element blocks. The dependencies have the same structure and function as under that base build. The major difference in this case is that instead of applying as dependencies of the project, they now apply as dependencies of the plugin that they are under. The power of this is to alter the dependency list of a plugin, perhaps by removing an unused runtime dependency via exclusions, or by altering the version of a required dependency.

That is, you can exclude some libraries from the plugin classpath or override certain versions, within the scope of that specific plugin.

Adding dependencies to a plugin would not alter the classpath of the application being built. The dependencies for a plugin is an entry point for further configurability, to directly change its classpath.

In most of the cases you would not need to work at that level of granularity, but indeed is quite useful in some cases and some plugin would actually need or recommend to add specific dependencies, for example plugins working on transformation or code generation (WSDL to Java, e.g.) would probably need a further dependency (you choose which one and which version) and so on.


A further official example is provided by the official Maven - Guide to configure plugins documentation:

You could configure the dependencies of the Build plugins, commonly to use a more recent dependency version.

For instance, the Maven Antrun Plugin version 1.2 uses Ant version 1.6.5, if you want to use the latest Ant version when running this plugin, you need to add <dependencies> element.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.2</version>
        ...
        <dependencies>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.7.1</version>
          </dependency>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-launcher</artifactId>
            <version>1.7.1</version>
          </dependency>
         </dependencies>
      </plugin>
    </plugins>
  </build>
  ...
</project>

Another example is provided by the official Exec Maven Plugin documentation in case you want to use its java goal to execute a Java program and you actually need to add libraries to its classpath but you don't want to alter the classpath of the application under build: this is a much cleaner and reasonable approach.

Community
  • 1
  • 1
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
0

Dependency in plugin element allows you to define a specific version you will like the plugin to use.

Here is a good example on maven.apache.org

For instance, the Maven Antrun Plugin version 1.2 uses Ant version 1.6.5, if you want to use the latest Ant version when running this plugin, you need to add <dependencies> element

Tunaki
  • 132,869
  • 46
  • 340
  • 423
LeTex
  • 1,452
  • 1
  • 14
  • 28
  • so after 15 minutes from my answer, you actually report the same thing, copy&paste: what's the point? – A_Di-Matteo Aug 27 '16 at 12:13
  • @sab why accepting this late answer when my earlier answer provided the information first and with more details? this answer was simply a cop&paste – A_Di-Matteo Aug 27 '16 at 12:22
  • 1
    @A_Di-Matteo I don't have intention of answering a question by copying another answer. I was in edit mode the moment the question was posted, and when I posted it, your answer was already there. I agree with you your answer is more detailed and must be taken as an answer. sab - if you could please accept the other answer instead. cheers. – LeTex Aug 27 '16 at 12:29
  • sorry about my wrong assumption, it can happen, the time difference between the two didn't let me think about that case. Anyway, about the accepted answer, well sometimes it goes like this in Stack Overflow, life goes on ;-) – A_Di-Matteo Aug 27 '16 at 12:47