View on GitHub

Mojo Executor

The Mojo Executor provides a way to to execute other Mojos (plugins) within a Maven plugin, allowing you to easily create Maven plugins that are composed of other plugins.

Download this project as a .zip file Download this project as a tar.gz file

The Mojo Executor provides a way to to execute other Mojos (plugins) within a Maven plugin, allowing you to easily create Maven plugins that are composed of other plugins.

News

25 Aug 2013 — Mojo Executor 2.1.0 released with support for Maven 3.1.

Downloads

You can download the jars, source, and javadocs from Maven central:

http://repo2.maven.org/maven2/org/twdata/maven/mojo-executor/

Example Usage

MojoExecutor defines a number of builder methods that are intended to be imported statically:

import static org.twdata.maven.mojoexecutor.MojoExecutor.*

This is how you would execute the "copy-dependencies" goal of the Maven Dependency Plugin programmatically:

executeMojo(
    plugin(
        groupId("org.apache.maven.plugins"),
        artifactId("maven-dependency-plugin"),
        version("2.0")
    ),
    goal("copy-dependencies"),
    configuration(
        element(name("outputDirectory"), "${project.build.directory}/foo")
    ),
    executionEnvironment(
        project,
        session,
        pluginManager
    )
);

The project, session, and pluginManager variables should be injected via the normal Mojo injection:

/**
 * The project currently being build.
 *
 * @parameter expression="${project}"
 * @required
 * @readonly
 */
private MavenProject mavenProject;

/**
 * The current Maven session.
 *
 * @parameter expression="${session}"
 * @required
 * @readonly
 */
private MavenSession mavenSession;

/**
 * The Maven BuildPluginManager component.
 *
 * @component
 * @required
 */
private BuildPluginManager pluginManager;

You might need to add other annotations to your Mojo class, depending on the needs of your plugin. Annotations declared by Mojos that you execute are not automatically inherited by your enclosing Mojo.

For example, if you are using the maven-dependency-plugin, as in this example, you will need to add @requiresDependencyResolution <scope> to your class annotations to ensure that Maven resolves the project dependencies before invoking your plugin.

See the Mojo API Specification for details on available annotations. Look at the included example plugin for an example of use.

Maven Dependency

Add this to your pom.xml:

<dependencies>
    <dependency>
        <groupId>org.twdata.maven</groupId>
        <artifactId>mojo-executor</artifactId>
        <version>2.1</version>
    </dependency>
</dependencies>

There are a few versions available, and the best one to use will depend on the version(s) of Maven you need to support:

License

Copyright 2008-2013 Don Brown

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributors

Mojo Executor was originally created by Don Brown (mrdon@twdata.org).

It is currently maintained by Tim Moore (tmoore@incrementalism.net).

Thanks to the following contributors, who have provided patches and other assistance: