Multiple pom files for a maven project

27,582

Yes you can use Maven Profiles to manage this.

E.g. in the parent POM create a profiles section

<profiles>
    <profile>
        <id>aggregate-all</id>
        <modules>
             <module>abc-codegen</module>
             <module>stellar-codegen</module>
             <module>abc-engine</module>
             <module>stellar-engine</module>
        </modules>
    </profile>
    <profile>
        <id>aggregate-codegen</id>
        <modules>
             <module>abc-codegen</module>
             <module>stellar-codegen</module>
        </modules>
    </profile>
</profiles>

Now to build everything you run:

mvn clean install -P aggregate-all

To build just the code generation projects you run

mvn clean install -P aggregate-codegen

Obviously you can tweak this approach to suit your needs however works best. So you could create a profile that builds just the engine projects.

Share:
27,582
Selvakumar Esra
Author by

Selvakumar Esra

Updated on July 10, 2022

Comments

  • Selvakumar Esra
    Selvakumar Esra almost 2 years

    i have a project which has multiple maven project and 1 parent pom which has all other projects as maven modules.

    pom.xml

    <modules>
        <module>abc-codegen</module>
        <module>stellar-codegen</module>
        <module>abc-engine</module>
        <module>stellar-engine</module>
    </modules>
    

    out of those maven projects few projects(abc-codegen, stellar-codegen) are used for code generation. the codegen artifacts are used by other maven modules such as abc-engine.

    the codegen modules may not be built everytime other application modules(abc-engine etc) are built and released.

    pom-codegen.xml

    <modules>
        <module>abc-codegen</module>
        <module>stellar-codegen</module>
    </modules>
    

    However, the codegen projects should remain inside the parent folder (svn/my-service/trunk) for the sake of consistency with other such applications.

    One of the idea i have is to create another pom file called as pom-codegen.xml under the parent folder and generate code when required by explicitely calling

    mvn -f pom-codegen.xml clean deploy
    

    The only i have to do is tell my CI to execute the above command and trigger deploy the artifact when required. whilst Other build (mvn clean install) will check the sanity of the code. can we do this any other approach?

  • Selvakumar Esra
    Selvakumar Esra about 10 years
    i have to make a profile work by default using <activeByDefault> in profile.