开发者

Maven Aggregate POM with Goal?

开发者 https://www.devze.com 2023-01-26 14:49 出处:网络
I have a Mave开发者_StackOverflow社区n POM that aggregates several modules. <project [stuff]>

I have a Mave开发者_StackOverflow社区n 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号