title: Maven tests run twice when a profile identifier is in multiple projects. Why?
body: <p>I have numerous projects in IntelliJ, each of which has a pom.xml, and each of the projects' poms inherit from the master pom.xml.  One profile (called test1) is present in two of the poms (for project2 and project4).  When I run maven from the command line, specifying one project and the profile name, it works (the tests in that project are executed once)  Here is the commmand:</p>
  
  <pre><code>mvn test -pl project2 -am -P test1
  </code></pre>
  
  <p>When I specify both projects (both of which have the same profile present), the tests in project4 are executed twice.  Here is the command:</p>
  
  <pre><code>mvn test -pl project2,project4 -am -P test1
  </code></pre>
  
  <p>I would like the tests only to be executed once.  I am running maven 3.1.1.</p>
  
  <p>As a further complication, when I specify just project4, the tests in project2 get executed once, and the tests in project4 don't get executed at all.  Here is the command:</p>
  
  <pre><code>mvn test -pl project4 -am -P test1
  </code></pre>
  
  <p>Here is pom.xml for project2:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;project xmlns stuff...&gt;
      &lt;parent&gt;
          &lt;artifactId&gt;parent artifact id&lt;/artifactId&gt;
          &lt;groupId&gt;group id&lt;/groupId&gt;
          &lt;version&gt;version&lt;/version&gt;
      &lt;/parent&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;name&gt;project2&lt;/name&gt;
  
      &lt;artifactId&gt;project2&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;test1&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-surefire-plugin&lt;/artifactId&gt;
                          &lt;version&gt;2.9&lt;/version&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;id&gt;execute-tests-1&lt;/id&gt;
                                  &lt;phase&gt;test&lt;/phase&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;test&lt;/goal&gt;
                                  &lt;/goals&gt;
                                  &lt;configuration&gt;
                                      &lt;skip&gt;false&lt;/skip&gt;
                                      &lt;excludes&gt;
                                          &lt;exclude&gt;com/path/to/exclude/**/*.java&lt;/exclude&gt;
                                      &lt;/excludes&gt;
                                  &lt;/configuration&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;!-- We don't want to run any tests without an active profile --&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;2.9&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;skip&gt;true&lt;/skip&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;!-- This exports the classes in the tests for use with our other modules' tests --&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.2&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;test-jar&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencies&gt;
          [ dependencies ...]
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Here is the pom.xml for project4:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;project xmlns stuff&gt;
      &lt;parent&gt;
          &lt;artifactId&gt;[parent artifact id]&lt;/artifactId&gt;
          &lt;groupId&gt;[group id]&lt;/groupId&gt;
          &lt;version&gt;[version]&lt;/version&gt;
      &lt;/parent&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;name&gt;project4&lt;/name&gt;
  
  
      &lt;artifactId&gt;project4&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;dependencies&gt;
          [ dependencies ...]
      &lt;/dependencies&gt;
  
      &lt;profiles&gt;
          &lt;profile&gt;
              &lt;id&gt;test1&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-surefire-plugin&lt;/artifactId&gt;
                          &lt;version&gt;2.9&lt;/version&gt;
                          &lt;executions&gt;
                              &lt;execution&gt;
                                  &lt;id&gt;execute-tests-2&lt;/id&gt;
                                  &lt;phase&gt;test&lt;/phase&gt;
                                  &lt;goals&gt;
                                      &lt;goal&gt;test&lt;/goal&gt;
                                  &lt;/goals&gt;
                                  &lt;configuration&gt;
                                      &lt;includes&gt;
                                          &lt;include&gt;com/path/to/tests/*.java&lt;/include&gt;
                                      &lt;/includes&gt;
                                  &lt;/configuration&gt;
                              &lt;/execution&gt;
                          &lt;/executions&gt;
                      &lt;/plugin&gt;
                  &lt;/plugins&gt;
              &lt;/build&gt;
              &lt;dependencies&gt;
                  [ dependencies...]
              &lt;/dependencies&gt;
          &lt;/profile&gt;
      &lt;/profiles&gt;
  &lt;/project&gt;
  </code></pre>