- Import maven plugin configuration by composition rather than inheritance. Can it be done with build extensions?
- <build>
- ...
- <plugins>
- <plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <execution>
- <id>printboy</id>
- <phase>none</phase>
- <configuration>
- <target>
- <echo message="@@@@@@@@@@@@ HELLO! Iam a BOY project"/>
- </target>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- <execution>
- <id>printkid</id>
- <phase>none</phase>
- <configuration>
- <target>
- <echo message="@@@@@@@@@@@@ HELLO! Iam a KID project"/>
- </target>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- <execution>
- <id>printgirl</id>
- <phase>none</phase>
- <configuration>
- <target>
- <echo message="@@@@@@@@@@@@ HELLO! Iam a GIRL project"/>
- </target>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- ...
- </build>
- <build>
- <extensions>
- <extension>
- <groupId>br.com.touchtec.maven.plugins</groupId>
- <artifactId>execution-enabler-extension</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </extension>
- </extensions>
- ...
- </build>
- @Component(role = AbstractMavenLifecycleParticipant.class, hint = "enableif")
- public class EnableIfExtension extends AbstractMavenLifecycleParticipant {
- @Override
- public void afterProjectsRead(MavenSession session)
- throws MavenExecutionException {
- String phase = "validate";
- for(MavenProject project : session.getProjects()){
- Properties properties = project.getProperties();
- if(properties != null){
- if("boy".equals(properties.getProperty("project_type"))){
- setExecutionPhase(project, "printboy", phase);
- setExecutionPhase(project, "printkid", phase);
- }
- if("girl".equals(properties.getProperty("project_type"))){
- setExecutionPhase(project, "printgirl", phase);
- setExecutionPhase(project, "printkid", phase);
- }
- if("kid".equals(properties.getProperty("project_type"))){
- setExecutionPhase(project, "printkid", phase);
- }
- }
- }
- }
- private void setExecutionPhase(MavenProject project, String executionId, String phase) {
- for(Plugin plugin : project.getBuild().getPlugins()){
- if(plugin.getExecutions() != null){
- for(PluginExecution execution : plugin.getExecutions()){
- if(executionId.equals(execution.getId())){
- execution.setPhase(phase);
- }
- }
- }
- }
- }
- }
- <project>
- <properties>
- <project_type>boy</project_type>
- </properties>
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.family</groupId>
- <artifactId>boy</artifactId>
- <version>1.0-SNAPSHOT</version>
- <packaging>pom</packaging>
- <parent>
- <groupId>com.family</groupId>
- <artifactId>daddy</artifactId>
- <version>1.0-SNAPSHOT</version>
- </parent>
- <!-- No "build" section. Beautifull. -->
- </project>