John LeBoeuf-Little
John LeBoeuf-Little

Reputation: 565

Maven Aggregate POM with Goal?

I have a Maven POM that aggregates several modules.

<project [stuff]>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fuhu.osg</groupId>
  <artifactId>UserManagement</artifactId>
  <packaging>pom</packaging>
  <version>1.0</version>
  <name>UserManagement</name>

  <modules>
   <module>core</module>
   <module>war</module>
   <module>ejbs</module>
   <module>ear</module>
  </modules>
</project>

I want to execute a goal that doesn't apply to the modules against the top-level POM. Something like mvn db-migrate:create. As is, it seems like this attempts to run said command against the sub-projects, which is correct for every OTHER goal, but not for this one.

Is there a way to make a Maven POM that is both an Aggregate for some goals and an ordinary project for others?

Upvotes: 5

Views: 3594

Answers (1)

Martin Algesten
Martin Algesten

Reputation: 13620

You might be helped by Maven build profiles. It's easy to configure one submodule to be invoked when using a certain profile.

http://maven.apache.org/guides/introduction/introduction-to-profiles.html

...
  <profiles>
    <profile>
      <id>db</id>
      <modules>
        <module>core</module>
      </modules>
    </profile>
    <profile>
      <id>all</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <modules>
        <module>core</module>
        <module>war</module>
        <module>ejbs</module>
        <module>ear</module>
      </modules>
    </profile>
...

Start your db task with the db profile with something like:

$ mvn -Pdb db-migrate:create

Auto activation of profiles is possible using system environment etc. Sadly I can't find a maven property for the command line goal, which would enable auto activation of a profile when that specific goal is run.

Upvotes: 8

Related Questions