title: How to skip integration tests by default but still run them on-demand in multi-module maven project?
body: <p>I have a multi module project having the following structure:    </p>
  
  <pre><code>Project:    
   - module1
   - module2
   - integration-test
   - parent pom
  </code></pre>
  
  <p>What is the correct way of achieving the following:   </p>
  
  <ul>
  <li>run unit tests from all modules(except integration-test) using <code>mvn clean install</code></li>
  <li>run integration tests on demand(may be by using maven-failsafe plugin or via a maven profile? )</li>
  <li>fail the build when integration tests fail.         </li>
  <li>By Default integration tests should not be run using <code>mvn clean install</code>   </li>
  <li>integration-test module has only the integration tests.</li>
  </ul>
  
  <p>I have tried multiple hacks using maven-failsafe plugin and maven-sunfire-plugin(for unit tests) but not able to achieve the above in standard way.</p>
  
  <p>Following is how the relevant portion of integration-test pom looks like:</p>
  
  <pre><code>&lt;dependencies&gt;
     &lt;!-- dependencies required for this module--&gt;
  
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.12&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;add-integration-test-sources&lt;/id&gt;
                      &lt;phase&gt;generate-test-sources&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;add-test-source&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;sources&gt;
                              &lt;source&gt;src/test/java&lt;/source&gt;
                          &lt;/sources&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;add-integration-test-resources&lt;/id&gt;
                      &lt;phase&gt;generate-test-resources&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;add-test-resource&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;resources&gt;
                              &lt;resource&gt;
                                  &lt;filtering&gt;true&lt;/filtering&gt;
                                  &lt;directory&gt;src/test/resources&lt;/directory&gt;
                              &lt;/resource&gt;
                          &lt;/resources&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt; 
      &lt;/plugins&gt;
  &lt;/build&gt;
  
  &lt;profiles&gt;
      &lt;profile&gt;
          &lt;id&gt;run-its&lt;/id&gt;
          &lt;build&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
                      &lt;executions&gt;
                          &lt;execution&gt;
                              &lt;goals&gt;
                                  &lt;goal&gt;integration-test&lt;/goal&gt;
                                  &lt;goal&gt;verify&lt;/goal&gt;
                              &lt;/goals&gt;
                          &lt;/execution&gt;
                      &lt;/executions&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/build&gt;
      &lt;/profile&gt;
  &lt;/profiles&gt;
  </code></pre>
  
  <p></p>
  
  <p>currently when i run <code>mvn clean install</code> it runs integration tests too. When i run <code>mvn -Prun-its clean verify</code>, it is running unit tests from other modules too. what am i missing?</p>