mavenmaven-profiles

Using different profiles for Maven Modules


I'm trying to work in a multimodule maven project. The whole company have a pom project where we have defined two maven profiles: application - it's used when we are building an application (zip have to be created, etc), module - when we are building a simple common module. Let's call this pom project as build.module

Now there is a maven multimodule project which is also using the build.module. This project contains two modules, one is the application (myapp) which should be built with "application" profile, and another one which is a common module (mycommon) which should be built with "module" profile.

If I run the mvn clean install to the multimodule there I can just specify the profiles used, but I don't want to be built both modules with the same profile, I would like to have some kind of control over them.

While I have multiple modules in the multimodule project there can be also defined additional profiles to control which modules should be built.

My question is how I could manage to build my multimodule project in a way that the myapp is built with "application" profile while the mycommon is built with "module" profile?

--> build module

-----> multimoduleproject

---------> mycommon

---------> myapp

Thank you so much, if you know how to do that you could help me a lot :)

Have a nice day.


Solution

  • We defined something like

    <profiles>
      <profile>
        <id>findbugs</id>
        <activation>
          <file>
            <exists>${basedir}/.mvn/active-profiles/findbugs</exists>
          </file>
        </activation>
        ...
    

    This allows you to activate findbugs by adding a file named findbugs to the respective directory. Your problem should be solvable along the same lines.

    A side remark: I decided to replace most of the profiles by properties (that skip/enable plugins) in the future because we want to gather all information inside the POM. Nevertheless, the solution with the profiles is working well for about 2 years now.