Skip to content

Maven Build Plugin

Ben Fagin edited this page Mar 1, 2016 · 9 revisions

Starting with version 0.4, a maven build plugin is available. This allows you to define your descriptor in a separate module, and have the code generation occur on the fly with each build.

There are several components:

  • The build plugin, which reads descriptors, generates sources, and compiles them. The plugin can also write out the runtime files so that consumers of your jar do not have to include the runtime jar either as a dependency or transitive dependency.
  • The runtime, either included as a dependency ('flapi-runtime') or embedded in your API jar.
  • The 'flapi-build-project' POM, which can be made the parent project of your descriptor module. This reduces the amount of configuration you will have to do to a few lines. It includes source and JavaDoc jar creation, but places them at the end of the build process to allow the generated sources to be included.

With the Parent POM

Using the parent pom, you only need to do the following in your own project:

  1. Create a new module or project for your builder API.
  2. Add Flapi as a 'test' scoped dependency.
  3. Add any other dependencies you need.
  4. Create any support classes you need in src/main.
  5. Add your DescriptorMaker implementations in src/test.
  6. Set the flapi.descriptor.classes property in your POM to a comma-separated list of the DescriptorMaker classes.
  7. Run mvn clean install to create the jars for your API.

An example of this setup is included in the project. See the build-test-producer and build-test-consumer modules.

The artifact information for the parent pom is as follows:

<parent>
    <groupId>com.unquietcode.tools.flapi</groupId>
    <artifactId>flapi-build-project</artifactId>
    <version>2.0</version>
</parent>

Without the Parent

If you are unable to make use of the preconfigured parent project, you can just include the plugin directly in your build.

<plugin>
    <groupId>com.unquietcode.tools.flapi</groupId>
    <artifactId>flapi-build-plugin</artifactId>
    <version>2.0</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <descriptorClasses>...</descriptorClasses>
	        <sourcesDirectory>...</sourcesDirectory>
                <includeRuntime>...</includeRuntime>
            </configuration>
        </execution>
    </executions>
</plugin>
Clone this wiki locally