Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - skip parent project build

I know it's mauvais ton to ask twice in a single day but here's another Maven puzzler:

I have a parent POM which defines 5 modules (5 subprojects). Since each module is executed in exactly the same way I pull <profile><build> section into the parent POM to get rid of the duplicate code. Now - if I execute build individually from each module it works, however if I want to build all modules at once and move to the parent directory I got error since the very first thing Maven tries to execute is the parent project itself:

mvn package -P release
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO]   DWD Parent project
[INFO]   Projects

After that build fails because exec plugin tries to execute something that is not there. Looking at the output it is pretty obvious that reactor plugin is driving the build but how can I configure reactor to skip the parent?

P.S. To prevent confusion - I'm trying to suppress profile execution on parent and enable it on child during the same build

like image 753
Bostone Avatar asked Oct 01 '09 00:10

Bostone


People also ask

How do I skip a project in Maven build?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.

Is parent tag mandatory in POM xml?

Now child POM need to refer the parent POM using parent tag and specifying groupId/artifactId/version attributes. This pom file will inherit all properties and dependencies from parent POM and additionally can include extra sub-project specific dependencies as well.

Can a Maven POM have 2 parents?

The base poms should be at the root of the hierarchy because the application itself also depends on it, or any other java module we build. It is just that next to that I also have this plugin structure which would need kind of 2 parents, but this is not possible it seems.


1 Answers

You can't skip the parent build, but you can configure the profile to not be activated with a little hack. This answer shows how to control the activation of a profile by the presence or absence of a file-based <activation> element. This way you can define the profile in the parent, but have it deactivated in that project because of the marker file being present in the parent. Child projects would not have the marker file in their source, so the profile would be activated for those projects.

Update to clarify: On my test project this configuration means the profile is deactivated in the parent project (which has the file in src/main/resources), but activated in all child projects which do not have the file in their resources directories.

<profile>
  <id>test</id>
  <activation>
    <file>
      <missing>src/main/resources/test.marker</missing>
    </file>
  </activation>
  ...
</profile>
like image 118
Rich Seller Avatar answered Sep 20 '22 23:09

Rich Seller