Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8341723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:34:07+00:00 2026-06-09T05:34:07+00:00

Import maven plugin configuration by composition rather than inheritance. Can it be done with

  • 0

Import maven plugin configuration by composition rather than inheritance. Can it be done with build extensions?

I have used maven for more than 3 years and there’s one shortcoming that has always bugged me.
It’s time to find a solution for that already.

The problem:

I have a “daddy” maven module with 3 children: “boy”, “girl”, and “kid”.
Each of these children must have its own distinct set of plugin configurations for a default “clean install” build.
I don’t want to put that configuration on the children’s poms. I’d rather put it somewhere that I can reuse later.

I have tried using profiles for that, and it doesn’t work – please see my comment and attached project on MNG-5127

I have found a better solution by making the following changes on the daddy.zip project:

1) On daddy’s pom, Replaced the [profiles] with plugin executions having [phase]none[/phase]

<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>

2) On the same pom, added a custom build extension

<build>
    <extensions>
        <extension>
            <groupId>br.com.touchtec.maven.plugins</groupId>
            <artifactId>execution-enabler-extension</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </extension>
    </extensions>
    ...
</build>

3) The extension will change the plugin execution phases based on the project’s property values. Java code below.

@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);
                    }
                }
            }
        }
    }
}

4) The child module poms only need to define a property that will tell the build extension what to do, for example, the boy project:

<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>

Invoking mvn clean install on the daddy project like thiss, will output the desired result: boys will be boys, girls will be girls and both will be kids.

The question is: can we do better?

In theory, a build extension could import the build configuration definitions for boy, girl, and kid from different poms… right?
That would be the a clever and elegant way of importing [build] configuration into a pom.

There are a lot of available maven plugins, but I don’t see a lot (actually any) of available build extensions that one can plug into a build.
Does anyone know of a build extension that helps with this?


Update

This is not an actual answer, but it’s an actual solution to my problem, so here goes.

Import maven plugin configuration by composition rather than inheritance. Can it be done with build extensions?

Probably

Does anyone know of a build extension that helps with this?

I’m pretty sure there isn’t one

However, there is a solution using profiles.

The trick is that file-based profile activation is actually inherited (it only works with maven3 though)

Please see the daddy2.zip attached to MNG-5127

This is way better than using the build extension strategy, because using a profile provides more flexibility than just changing a few plugin execution phases.


Update 2

Does anyone know of a build extension that helps with this?

I’m pretty sure there isn’t one

Actually there is something!

It’s attached as project in MNG-5102 (by Maurizio Pillitu)
I haven’t tested it, but it seems it does something very close to the proposed build extension.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:34:09+00:00Added an answer on June 9, 2026 at 5:34 am

    I think that Maven Tiles can help you with your specific use-case.
    It is still work in progress, but it currently accomplishes what you’re describing, I managed to “decompose” the wicket-quickstart and run Jetty successfully, even adding a multi-module structure.

    Any comment or hint is more than welcome.
    Thanks,
    Maurizio

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: I'm just getting started with Jenkins plugin development and have never used maven
I use the m2eclipse plugin in Eclipse so that I can import a Maven
I have one bundle using the following configuration in pom.xml: <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.1.0</version>
I cannot import a maven project with WTP features enabled. I have already tried:
I have been able to run some web services locally through Maven's jetty plugin
I think I am misunderstanding something import with the maven-release-plugin. I am able to
We have a big (~215 bundles and counting) osgi (felix+springdm) project, build with maven
I have openNMS 1.8.12-1 source code and trying to build it using maven and
I have a java library. I build it with Maven. I want to make
With the maven eclipse plugin, I can configure checkstyle or sonar configurations by adding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.