title: Maven configuration with Spring Boot & multi modules - run application in Intellij
body: <p>I'm currently working on a REST API with Spring Boot.</p>
  
  <p>I'm new to Maven and have just started coding with IDEA (don't know well this IDE yet), and I have a problem...</p>
  
  <p>Here is my project structure :</p>
  
  <ul>
  <li>parent
  <ul>
  <li>pom.xml</li>
  <li>main module
  <ul>
  <li>controller</li>
  <li>domain</li>
  <li>App.java (Spring Boot main class)</li>
  <li>pom.xml</li>
  </ul></li>
  <li>sub module (need main module as dependency)
  <ul>
  <li>controllers</li>
  <li>domain</li>
  <li>pom.xml</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>So when I run the project in Intellij, it starts, and I can access all URLs defined in the main module controller. But not the ones in the sub module controller... It looks like only the main module was loaded.</p>
  
  <p>Here is my parent pom.xml :</p>
  
  <pre><code>&lt;project&gt;
  
  &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.2.1.RELEASE&lt;/version&gt;
  &lt;/parent&gt;
  
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;name&gt;Test :: Test :: Parent POM&lt;/name&gt;
  
  &lt;groupId&gt;test.test.test&lt;/groupId&gt;
  &lt;artifactId&gt;project-parent&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
  
  &lt;properties&gt;
      &lt;!-- Specify Java Compiler Version --&gt;
      &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
  
      &lt;!-- Spring --&gt;
      &lt;spring-boot.version&gt;1.2.1.RELEASE&lt;/spring-boot.version&gt;
  
      &lt;!-- Sonar --&gt;
      &lt;sonar-maven-plugin.version&gt;2.5&lt;/sonar-maven-plugin.version&gt;
      &lt;sonar.language&gt;java&lt;/sonar.language&gt;
      &lt;sonar.core.codeCoveragePlugin&gt;jacoco&lt;/sonar.core.codeCoveragePlugin&gt;
      &lt;sonar.dynamicAnalysis&gt;reuseReports&lt;/sonar.dynamicAnalysis&gt;
      &lt;sonar.jacoco.reportPath&gt;${project.basedir}/../target/jacoco.exec&lt;/sonar.jacoco.reportPath&gt;
  
      &lt;!-- Plugin --&gt;
      &lt;maven-surefire-plugin.version&gt;2.18.1&lt;/maven-surefire-plugin.version&gt;
      &lt;jacoco-maven-plugin.version&gt;0.7.3.201502191951&lt;/jacoco-maven-plugin.version&gt;
  
  
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
  &lt;/properties&gt;
  
  &lt;modules&gt;
      &lt;module&gt;submodule&lt;/module&gt;
      &lt;module&gt;main&lt;/module&gt;
  &lt;/modules&gt;
  
  &lt;build&gt;
      &lt;pluginManagement&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${maven-surefire-plugin.version}&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;redirectTestOutputToFile&gt;true&lt;/redirectTestOutputToFile&gt;
                      &lt;includes&gt;
                          &lt;include&gt;**/*Test.java&lt;/include&gt;
                          &lt;include&gt;**/*IT.java&lt;/include&gt;
                          &lt;include&gt;**/*Story.java&lt;/include&gt;
                      &lt;/includes&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
  
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
              &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;${jacoco-maven-plugin.version}&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;destFile&gt;${project.basedir}/../target/jacoco.exec&lt;/destFile&gt;
              &lt;/configuration&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;prepare-agent&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
  
          &lt;plugin&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;sonar-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;${sonar-maven-plugin.version}&lt;/version&gt;
          &lt;/plugin&gt;
  
      &lt;/plugins&gt;
  &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>Here my main module pom.xml :</p>
  
  <pre><code>&lt;project&gt;
  &lt;parent&gt;
      &lt;artifactId&gt;project-parent&lt;/artifactId&gt;
      &lt;groupId&gt;test.test.test&lt;/groupId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;/parent&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;artifactId&gt;main&lt;/artifactId&gt;
  
  &lt;name&gt;Test :: Test :: Main&lt;/name&gt;
  
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  
      &lt;commons-lang3.version&gt;3.3.2&lt;/commons-lang3.version&gt;
      &lt;commons-codec.version&gt;1.10&lt;/commons-codec.version&gt;
      &lt;jsr305.version&gt;3.0.0&lt;/jsr305.version&gt;
  
      &lt;!-- Testing dependencies --&gt;
      &lt;http-commons.version&gt;4.3.6&lt;/http-commons.version&gt;
      &lt;jbehave.version&gt;3.9.5&lt;/jbehave.version&gt;
      &lt;assertj.version&gt;1.7.1&lt;/assertj.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.google.code.findbugs&lt;/groupId&gt;
          &lt;artifactId&gt;jsr305&lt;/artifactId&gt;
          &lt;version&gt;${jsr305.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
          &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;
          &lt;version&gt;${commons-lang3.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;commons-codec&lt;/groupId&gt;
          &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;
          &lt;version&gt;${commons-codec.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Test dependencies --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.h2database&lt;/groupId&gt;
          &lt;artifactId&gt;h2&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;version&gt;9.1-901-1.jdbc4&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
          &lt;version&gt;${http-commons.version}&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;fluent-hc&lt;/artifactId&gt;
          &lt;version&gt;${http-commons.version}&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
          &lt;artifactId&gt;spring-data-commons&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jbehave&lt;/groupId&gt;
          &lt;artifactId&gt;jbehave-spring&lt;/artifactId&gt;
          &lt;version&gt;${jbehave.version}&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.assertj&lt;/groupId&gt;
          &lt;artifactId&gt;assertj-core&lt;/artifactId&gt;
          &lt;version&gt;${assertj.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  
  &lt;!-- Package as an executable jar --&gt;
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>And here the sub module pom.xml :</p>
  
  <pre><code>&lt;project&gt;
  &lt;parent&gt;
      &lt;artifactId&gt;project-parent&lt;/artifactId&gt;
      &lt;groupId&gt;test.test.test&lt;/groupId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;/parent&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;artifactId&gt;submodule&lt;/artifactId&gt;
  
  &lt;name&gt;Test :: Test :: Submodule&lt;/name&gt;
  
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  
      &lt;commons-lang3.version&gt;3.3.2&lt;/commons-lang3.version&gt;
      &lt;commons-codec.version&gt;1.10&lt;/commons-codec.version&gt;
      &lt;jsr305.version&gt;3.0.0&lt;/jsr305.version&gt;
  
      &lt;!-- Testing dependencies --&gt;
      &lt;http-commons.version&gt;4.3.6&lt;/http-commons.version&gt;
      &lt;jbehave.version&gt;3.9.5&lt;/jbehave.version&gt;
      &lt;assertj.version&gt;1.7.1&lt;/assertj.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;test.test.test&lt;/groupId&gt;
          &lt;artifactId&gt;main&lt;/artifactId&gt;
          &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>I think that's correct, but not sure...
  I run the project in Intellij with Maven with config :</p>
  
  <ul>
  <li>working directory is root (not sub-module)</li>
  <li>command line <code>mvn spring-boot:run -Drun.arguments=--spring.profiles.active=dev -e -pl main</code></li>
  <li>property start-class with parent.main.App </li>
  </ul>
  
  <p>Need your help to configure all that stuff to run Spring Boot with all sub-modules loaded in the IDE for dev purpose... because I readlly don't know what is wrong in my config !</p>
  
  <p>Thx !</p>