`

maven generate customised mojo using annotation

 
阅读更多

1. create your own Mojo java class with annotation

@Mojo(name = "sayhi")
public class MyMojo extends AbstractMojo
{
   @Parameter(property="sayhi.location") // seems not working
   private String outputDirectory; // use this exact name when initialize in configure
...
}

 2. in the pom, pay attention the following points, it will generate maven plugin description for you.

 

<packaging>maven-plugin</packaging>
...
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-plugin-plugin</artifactId>
				<version>3.3</version>
				<configuration>
					<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
				</configuration>
				<executions>
					<execution>
						<id>mojo-descriptor</id>
						<goals>
							<goal>descriptor</goal>
						</goals>
					</execution>

				</executions>
			</plugin>
		</plugins>
	</build>

 

3. when using it, following the below steps (the "outputDirectory" matches the variable name in java.

<build>
		<plugins>
			<plugin>
				<groupId>au.gov.immi</groupId>
				<artifactId>first-mojo</artifactId>
				<version>0.0.1-SNAPSHOT</version>
				  <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>sayhi</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                	<outputDirectory>c:\temp</outputDirectory>
                </configuration>
			</plugin>
		</plugins>

	</build>

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics