Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Maven, what is the difference between an extension and a plugin

Tags:

maven

What is the functional difference between an extension and a plugin in Maven?

The below examples are taken from here which provides a brief summary but doesn't explain the difference well.

Extension example:

<project>
  ...
  <build>
    <extensions>
      <extension>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-ftp</artifactId>
        <version>2.10</version>
      </extension>
    </extensions>
  </build>
  ...
</project>

Plugin example:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          ...
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>
like image 505
TerekC Avatar asked Apr 07 '17 17:04

TerekC


People also ask

What is the difference between extension and plugin?

The main difference is that extensions are usually just source code, but plug-ins are always executables (i.e. object code). As of 2021, plug-ins have been deprecated by most browsers, while extensions are widely used.

What is extension in Maven?

A Maven extension is a library that goes into Maven Core classloader, then is really in the core execution of Maven, unlike a plugin that runs in a child classloader separated from other plugins.

What is difference between plugin and dependency 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.

What are the two types of Maven plugins?

Introduction. In Maven, there are two kinds of plugins, build and reporting: Build plugins are executed during the build and configured in the <build/> element. Reporting plugins are executed during the site generation and configured in the <reporting/> element.


1 Answers

From the docs:

Extensions are a list of artifacts that are to be used in this build. They will be included in the running build's classpath. They can enable extensions to the build process (such as add an ftp provider for the Wagon transport mechanism), as well as make plugins active which make changes to the build lifecycle. In short, extensions are artifacts that activated during build. The extensions do not have to actually do anything nor contain a Mojo. For this reason, extensions are excellent for specifying one out of multiple implementations of a common plugin interface.

The above are usually call build extensions which are often use the org.apache.maven.AbstractMavenLifecycleParticipant for particular usage.

A plugin which is defined with

<extension>true</extension>

will usually define it's own life cycle or packaging types like the maven-bundle-plugin which makes it possible to define a <packaging>bundle</packaging> or Maven Tycho defines packaging types: <packaging>eclipse-plugin</packaging>.

like image 136
khmarbaise Avatar answered Jan 02 '23 22:01

khmarbaise