带有 Mojo Javadoc 标签的 Java Maven 插件工具

Java 的 Maven 插件工具是java-javadocmaven -plugin-tools-api的实现,用于提取用 Mojo Javadoc 标签注释的 Java 编写的插件的描述符。

支持的 Mojo Javadoc 标签

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;

/**
 * Mojo Description: goal is the only required annotation.
 *
 * @goal <goalName>
 * @aggregator
 * @configurator <roleHint>
 * @execute phase="<phaseName>" lifecycle="<lifecycleId>" goal="<goalName>"
 * @executionStrategy <once-per-session|always> (unsupported since Maven 3.0)
 * @inheritByDefault <true|false> (unsupported since Maven 3.0)
 * @instantiationStrategy <per-lookup|singleton|keep-alive|poolable>
 * @phase <phaseName>
 * @requiresDependencyResolution <compile|runtime|compile+runtime|test>
 * @requiresDependencyCollection <compile|runtime|compile+runtime|test> (since Maven 3.0)
 * @requiresDirectInvocation <false|true> (unsupported since Maven 3.0)
 * @requiresOnline <false|true>
 * @requiresProject <true|false>
 * @requiresReports <false|true> (unsupported since Maven 3.0)
 * @threadSafe (since Maven 3.0)
 * @since <since-text>
 * @deprecated <deprecated-text>
 */
public class MyMojo
    extends AbstractMojo
{
    /**
     * @parameter name="parameter" alias="myAlias" implementation="" property="aProperty" default-value="${anExpression}"
     * @readonly
     * @required
     * @since <since-text>
     * @deprecated <deprecated-text>
     */
    private String parameter;

    /**
     * @component role="..." roleHint="..."
     */
    private Component component;

    // sample objects taken from Maven API through PluginParameterExpressionEvaluator

    /**
     * @parameter default-value="${session}"
     * @readonly
     */
    private MavenSession session;

    /**
     * @parameter default-value="${project}"
     * @readonly
     */
    private MavenProject project;

    /**
     * @parameter default-value="${mojoExecution}"
     * @readonly
     */
    private MojoExecution mojo;

    /**
     * @parameter default-value="${plugin}" // Maven 3 only
     * @readonly
     */
    private PluginDescriptor plugin;

    /**
     * @parameter default-value="${settings}"
     * @readonly
     */
    private Settings settings;

    /**
    * @parameter default-value="${project.basedir}"
    * @readonly
    */
    private File basedir;

    /**
    * @parameter default-value="${project.build.directory}"
    * @readonly
    */
    private File target;

    public void execute()
    {
        ...
    }
}

注意:在 3.0 之前,property被 , 替换为expressionrequired ${ }( expression="${aProperty}"),但从 3.0 开始,您可以省略它 ( expression="aProperty"),或者最好使用property="aProperty".

也可以看看