// This module is included in the following assembly:
// as_developing-extensions.adoc

[id='using-maven-to-generate-extension-definitions_{context}']
= Description of Maven plugin that supports extensions

The `extension-maven-plugin` supports extension development by
packaging the extension as a valid Spring Boot module. For step extensions
that you implement in Java, this plugin can generate the 
extension definition JSON file. 

In your Maven project's `pom.xml` file, add the following plugin declaration:

[source,xml]
----
<plugin>
    <groupId>io.syndesis.extension</groupId>
    <artifactId>extension-maven-plugin</artifactId>
    <version>${syndesis.version}</version>
    <executions>
        <execution>
        <goals>
            <goal>generate-metadata</goal>
            <goal>repackage-extension</goal> 
        </goals>
        </execution>
    </executions>
</plugin>
----

The `extension-maven-plugin` defines the following goals:

* *generate-metadata* generates the JSON extension definition file 
that will be in the generated JAR file as follows:
+
.. Maven starts with the data structure specifications that are in the 
`META-INF/syndesis/syndesis-extension-definition.json` file, if there
is one.
+
If you are coding in XML, then you must define the extension 
definition JSON file yourself and it must specify all required
data structures. 
+
If you are developing a connector or library extension, then you must
define the extension definition JSON file yourself and it must specify
all required data structures. 
+
If you are developing a step extension in Java, you can: 
+
** Create the extension definition JSON file yourself. 
** In your Java code, specify annotations that define all 
required data structures. You do not create an extension definition
JSON file.
** Create an extension definition JSON file and specify some but
not all  data structures. 

.. For step extensions that you develop in Java,
 Maven obtains missing specifications from code annotations

.. Maven adds the dependencies list, which specifies dependencies that are 
provided with a scope of `provided` and that are managed through the 
`extension-bom`. 

* *repackage-extension* packages the extension.
+
** Dependencies and related transitive dependencies 
that are not managed through the `extension-bom` are in the `lib` folder 
of the generated JAR. 
** For library extensions, dependencies whose scope is `system` are 
in the `lib` folder of the generated JAR.  

For example, suppose your Maven project has the following `pom.xml` file:

[source,xml]
----
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company</groupId>
  <artifactId>my-extension</artifactId>
  <version>1.0.0</version>
  <name>MyExtension</name>
  <description>A Sample Extension</description>
  <packaging>jar</packaging>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.syndesis.extension</groupId>
        <artifactId>extension-bom</artifactId>
        <version>1.3.10</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>io.syndesis.extension</groupId>
      <artifactId>extension-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.github.lalyos</groupId>
      <artifactId>jfiglet</artifactId>
      <version>0.0.8</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>io.syndesis.extension</groupId>
        <artifactId>extension-maven-plugin</artifactId>
        <version>1.3.10</version>
        <executions>
          <execution>
            <goals>
              <goal>generate-metadata</goal>
              <goal>repackage-extension</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
----

Based on this `pom.xml` file, the generated extension definition 
JSON file looks like this:

[source,json]
----
{
  "name": "MyExtension",
  "description": "A Sample Extension",
  "extensionId": "com.company:my-extension",
  "version": "1.0.0",
  "dependencies": [ {
    "type": "MAVEN",
    "id": "io.syndesis.extension:extension-api:jar:1.3.10"
  } ],
  "extensionType": "Libraries",
  "schemaVersion": "v1"
}
----

The generated archive has this structure and content:

[source]
----
my-extension-1.0.0.jar
|
+- lib
|  |
|  + jfiglet-0.0.8.jar
|
+- META-INF
  |
  +- MANIFEST.MF
     |
     +- syndesis
        |
        +- syndesis-extension-definition.json
----
