Search code examples
maven-2maven

How to exclude a module from a Maven reactor build?


We have a Maven 2 project with lots of modules in it. Example:

<modules>
  <module>common</module>
  <module>foo</module>
  <module>data</module>
  <module>bar</module>
  ... more ...
</module>

Let's say the "data" module is time consuming to build and we want to exclude it when the project is build by a CI server. Currently we use two pom.xml files to achieve this. One has all modules in it and the other one has all modules except the ones which can be left out for CI. But that's pretty annoying because sometimes we forget to put a new module into both files.

Is there a solution which doesn't need two separate module lists?


Solution

  • The easiest might be to use profiles like this:

    <project>
      ...
      <modules>
        <module>common</module>
        <module>foo</module>
        <module>bar</module>
      <modules>
      ...
      <profiles>
        <profile>
          <id>expensive-modules-to-build</id>
          <modules>
            <module>data</module>
          </modules>
        </profile>
      </profiles>
    </project>
    

    You should then check out ways you can activate profiles