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?
Maven's Multi-Module Project The submodules are regular Maven projects, and they can be built separately or through the aggregator POM. By building the project through the aggregator POM, each project that has a packaging type different from pom will result in a built archive file.
You can achieve multiple inheritance with profiles: This is not ideal because child projects cannot control the activation of profiles defined in the parent POM. This is not remotely related to inheritance. But you can use them to setup some parameters to turn on/off with a switch (enabling/disabling the profiles).
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project.
The mechanism in Maven that handles multi-module projects is referred to as the reactor. This part of the Maven core does the following: Collects all the available modules to build. Sorts the projects into the correct build order.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With