Create a New Doxia Macro

You need to add the following plexus-component-metadata plugin configuration to generate the correct Plexus component.xml file from annotations for the project containing your macro:

<project>
  ...
  <build>
    ...
    <plugins>
      <plugin>
        <groupId>org.codehaus.plexus</groupId>
        <artifactId>plexus-component-metadata</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>generate-metadata</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  ...
  </build>
  ...
</project>

You should implement the AbstractMacro class:

import org.apache.maven.doxia.macro.AbstractMacro;

/**
 * @plexus.component role="org.apache.maven.doxia.macro.Macro" role-hint="my"
 */
public class MyMacro
    extends AbstractMacro
{
...
    public void execute( Sink sink, MacroRequest request )
        throws MacroExecutionException
    {
        String myValue = (String) request.getParameter( "myParam" );
...
    }
...
}

To use it, you need to write the following markups:

  • APT
    %{my|myParam=myValue} <!-- my is the macro name defined by role-hint -->
  • XDoc
    <macro name="my"> <!-- my is the required macro name defined by role-hint -->
      <param name="myParam" value="myValue"/>
    </macro>