Q:

mvn clean install only builds parent module, child modules are not getting build in multi module maven project

Below is the  project structure
parent
--pom.xml
    --child1
      --pom.xml
    --child2
      --pom.xml

When I do maven clean install,  maven  only scan parent pom and  only do build on parent pom which has no logic at all. Somehow Maven doesn't build Child1 and child 2.
Parent pom.xml  
<groupId>com.demo.parent</groupId>
<artifactId>demo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo-parent</name>
<description>demo</description>
<profiles>
    <profile>
        <modules>
            <module>demo-child1</module>
            <module>demo-child2</module>           
        </modules>
    </profile>
</profiles>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
//omit dependency

Child1
<parent>
    <groupId>com.demo.parent</groupId>
    <artifactId>demo-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.demo.child1</groupId>
<artifactId>demo-child1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo.child1</name>
<description>demo.child1</description>
<packaging>pom</packaging>
//omit dependency

same for child2.
Maven build output
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building demo-parent 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo-parent ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ littleluck-parent ---
[INFO] Installing D:\demo\demo-parent\pom.xml to ommit-user\.m2\repository\com\demo\parent\demo-parent\0.0.1-SNAPSHOT\demo-parent-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.633 s
[INFO] Finished at: 2019-02-17T18:41:48-05:00
[INFO] Final Memory: 12M/155M
[INFO] ------------------------------------------------------------------------

I expected when I run maven clean install on parent pom.xml, maven should be able to scan both childs and make build, but currently it only make build on parent. 
Need some  help.

A:

The problem is that Maven is not seeing your modules directive, because the profile is not active. To run using a profile, give the profile an id and specify it on the command line, as follows:
mvn install -Pmy-profile

To add an id, update as follows:
<profile>
  <id>my-profile</id>
  <modules>
    <module>demo-child1</module>
    <module>demo-child2</module>
  </modules>
</profiles>

Another option is to mark the profile as the default, as follows:
<profile>
  <id>my-profile</id>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <modules>
    <module>demo-child1</module>
    <module>demo-child2</module>
  </modules>
</profiles>

This eliminates the need to specify a profile id at the command line.
However, unless there is a specific reason to define modules inside a profile, you should pull it out and declare them at the project level, as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.demo.parent</groupId>
  <artifactId>demo-parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>demo-parent</name>
  <description>demo</description>
  <packaging>pom</packaging>

  <modules>
    <module>demo-child1</module>
    <module>demo-child2</module>
  </modules>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>

