是否有可能拥有一个MOJO,其中有BaseSettings
和MavenSettings
的实例以这种方式使用,或者我被强迫进行" polute"这些字段直接进入我的MOJO?
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Parameter;
public abstract class SomeSpecialAbstractMojo extends AbstractMojo{
@Parameter
protected BaseSettings baseSettings = new BaseSettings();
@Parameter
protected MavenSettings mavenSettings = new MavenSettings();
}
-
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
public class MavenSettings {
@Parameter(name = "project", property = "project", readonly = true, required = true)
protected MavenProject project;
@Component
protected MavenProjectHelper projectHelper;
}
-
import org.apache.maven.plugins.annotations.Parameter;
public class BaseSettings {
@Parameter(name = "skip", defaultValue = "false")
protected boolean skip = false;
@Parameter(name="verbose", defaultValue = "true")
protected boolean verbose = true;
}
我们的想法是将一些通用属性捆绑到他们自己的" space"中,这使我的MOJO更小,而且我的代码更有条理。
修改 我想要这种执行配置:
<configuration>
<baseSettings>
<verbose>true</verbose>
</baseSettings>
<!-- mavenSettings is omitted, I want to "auto-use-default" here -->
<otherComplexSettings>
<complexValue1>value1</complexValue1>
</otherComplexSettings>
</configuration>
<executions>
<execution>
<id>goal1-call</id>
<goals>
<goal>mojo1</goal>
</goals>
<configuration>
<otherComplexSettings>
<complexValue1>override-value1</complexValue1>
</otherComplexSettings>
</configuration>
</execution>
<execution>
<id>goal2-call</id>
<goals>
<goal>mojo2</goal>
</goals>
<configuration>
<!-- only part of mojo2 -->
<anotherComplexSettings>
<complexValue3>value3</complexValue3>
</anotherComplexSettings>
</configuration>
</execution>
<execution>
<id>goal3-call</id>
<goals>
<goal>mojo3</goal>
</goals>
<configuration>
<otherComplexSettings>
<complexValue1>override-value012</complexValue1>
</otherComplexSettings>
</configuration>
</execution>
<execution>
<id>goal4-call</id>
<goals>
<goal>mojo4</goal>
</goals>
</execution>
</executions>