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?
To simplify building multiple projects, you can optionally create an aggregate Maven project. This consists of a single POM file (the aggregate POM), usually in the parent directory of the individual projects. The POM file specifies which sub-projects (or modules) to build and builds them in the specified order.
From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project. In the list that opens, select Run Maven Goal. In the Select Maven Goal dialog, specify a project and a goal that you want to execute before launching the project. Click OK.
model version is the version of project descriptor your POM conforms to. It needs to be included and is set. The value 4.0. 0 just indicated that it is compatible Maven 3.
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.
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