I don’t know exactly what your second question means. Maybe they really are not connected. But I am trying to answer both questions, starting with the first.
Question 1: How to call a target from another target?
You can use the Apache Maven Invoker for this .
Add the Maven dependency to your plugin.
For example:
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-invoker</artifactId>
<version>2.2</version>
</dependency>
And then you can call up another target as follows:
final Properties properties = new Properties();
properties.setProperty("example.param.one", exampleValueOne);
final InvocationRequest invocationRequest = new DefaultInvocationRequest();
invocationRequest.setPomFile(new File(pom));
invocationRequest.setGoals(Collections.singletonList("second-plugin:example-goal"));
invocationRequest.setProperties(properties);
final Invoker invoker = new DefaultInvoker();
invoker.setOutputHandler(new LogOutputHandler(getLog()));
final InvocationResult invocationResult = invoker.execute(invocationRequest);
Question 2: How can I share options between mojos?
You meant:
- ?
(. " 2.1" ) - "meta mojo" " "?
(. " 2.2" )
2.1:
, .
:
abstract class AbstractMyPluginMojo extends Abstract Mojo {
@Parameter(required = true)
private String someParam;
protected String getSomeParam() {
return someParam;
}
}
@Mojo(name = "first-mojo")
public class MyFirstMojo extends AbstractMyPluginMojo {
public final void execute() {
getLog().info("someParam: " + getSomeParam());
}
}
@Mojo(name = "second-mojo")
public class MySecondMojo extends AbstractMyPluginMojo {
public final void execute() {
getLog().info("someParam: " + getSomeParam());
}
}
maven. , Apache Maven Plugin.
2.2:
1. "-", properties.