How do I run selected modules using parent pom in Maven like I have

Refresh

April 2019

Views

1.3k time

1
<module>APP_1</module>
<module>web_1</module>
<module>service_1</module>
<module>schema_1</module>

<module>APP_2</module>
<module>web_2</module>
<module>service_2</module>
<<module>schema_2</module>

sometimes as developer if I want to build first module with all it's depedecies only so how should I achieve this task in parent pom? maven 3.0.3 jdk-1.6

2 answers

3

You can use the -pl or --projects parameter of maven command-line for this.

e.g.

mvn --p APP_1

This will build APP_1 and its dependant modules.

2

Use profile in parent pom:

</profiles>
  <profile>
    <!-- Build App 1 -->
    <id>app1</id>
    <modules>
      <module>APP_1</module>
      <module>web_1</module>
      <module>service_1</module>
      <module>schema_1</module>
    </modules>
  </profile>
  <profile>
    <!-- Build App 2 -->
    <id>app2</id>
    <modules>
      <module>APP_2</module>
      <module>web_2</module>
      <module>service_2</module>
      <<module>schema_2</module>
    </modules>
  </profile>
</profiles>

To build App1:

mvn clean install -Papp1

To build App2:

mvn clean install -Papp2