title: How to properly set up multi profile maven project?
body: <p>Hey, I'm talking about profiles within pom.xml of a project. Could please anybody explain to me, why if I have 2 profiles in pom definition and I run test phase from one of the profiles, both the Main method is executed and all the tests are run by surefire plugin ? I mean, even the surefire plugin runs all the tests, even though it is within a different profile ?</p>
  
  <pre><code>mvn test -Pcode-generator
  </code></pre>
  
  <p>the first one,code-generator, is just for Main methods execution and the second one for the rest of the project.</p>
  
  <pre><code>&lt;profiles&gt;
      &lt;profile&gt;
          &lt;id&gt;code-generator&lt;/id&gt;
          &lt;build&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                      &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                      &lt;version&gt;1.1.1&lt;/version&gt;
                      &lt;executions&gt;
                          &lt;execution&gt;
                              &lt;phase&gt;test&lt;/phase&gt;
                              &lt;goals&gt;
                                  &lt;goal&gt;java&lt;/goal&gt;
                              &lt;/goals&gt;
                              &lt;configuration&gt;
                                  &lt;mainClass&gt;cz.instance.transl.Main&lt;/mainClass&gt;
                                  &lt;arguments&gt;
                                      &lt;argument&gt;arg0&lt;/argument&gt;
                                      &lt;argument&gt;arg1&lt;/argument&gt;
                                  &lt;/arguments&gt;
                              &lt;/configuration&gt;
                          &lt;/execution&gt;
                      &lt;/executions&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/build&gt;
      &lt;/profile&gt;
  
      &lt;profile&gt;
          &lt;id&gt;default&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-war-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.1&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;warName&gt;${war.file.name}&lt;/warName&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&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.7&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;useFile&gt;false&lt;/useFile&gt;
                          &lt;argLine&gt;-Dportal.test=generic
                              -Dwebdriver.chrome.driver="/opt/google/chrome/chromedriver"
                              -Dwebdriver.development=true
                              -Dwebdriver.firefox.useExisting=true
                              -Dwebdriver.firefox.profile=webdriver
                              -Dwebdriver.reap_profile=true
                              -Dsurefire.useFile=false
                              -Xmx2048M
                              -XX:MaxPermSize=1048M
                              -XX:+CMSClassUnloadingEnabled
                  &lt;/argLine&gt;
                          &lt;skipTests&gt;false&lt;/skipTests&gt;
  
                          &lt;suiteXmlFiles&gt;
                              &lt;suiteXmlFile&gt;${basedir}/src/test/resources/testng.xml&lt;/suiteXmlFile&gt;
                          &lt;/suiteXmlFiles&gt;
  
                          &lt;systemProperties&gt;
                              &lt;property&gt;
                                  &lt;name&gt;log4j.configuration&lt;/name&gt;
                                  &lt;value&gt;META-INF/log4j.xml&lt;/value&gt;
                              &lt;/property&gt;
                          &lt;/systemProperties&gt;
  
                          &lt;includes&gt;
                              &lt;include&gt;cz/instance/transl/tests/selenium/*Test.java&lt;/include&gt;
                          &lt;/includes&gt;
                          &lt;excludes&gt;
                              &lt;exclude&gt;cz/instance/transl/tests/sample/*Test.java&lt;/exclude&gt;
                          &lt;/excludes&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
  
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-surefire-report-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.7.1&lt;/version&gt;
                      &lt;!-- &lt;configuration&gt; &lt;useFile&gt;false&lt;/useFile&gt; &lt;/configuration&gt; --&gt;
                  &lt;/plugin&gt;
  
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.3.2&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;encoding&gt;UTF-8&lt;/encoding&gt;
                          &lt;source&gt;1.5&lt;/source&gt;
                          &lt;target&gt;1.5&lt;/target&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
  
              &lt;testResources&gt;
                  &lt;testResource&gt;
                      &lt;directory&gt;${project.basedir}/src/test/java&lt;/directory&gt;
                      &lt;includes&gt;
                          &lt;include&gt;**/*.*&lt;/include&gt;
                      &lt;/includes&gt;
                  &lt;/testResource&gt;
                  &lt;testResource&gt;
                      &lt;directory&gt;${project.basedir}/src/test/resources&lt;/directory&gt;
                      &lt;includes&gt;
                          &lt;include&gt;**/*&lt;/include&gt;
                      &lt;/includes&gt;
                  &lt;/testResource&gt;
              &lt;/testResources&gt;
  
              &lt;resources&gt;
                  &lt;resource&gt;
                      &lt;directory&gt;${project.basedir}/src/main/java&lt;/directory&gt;
                      &lt;includes&gt;
                          &lt;include&gt;**/*.java&lt;/include&gt;
                          &lt;include&gt;service.properties&lt;/include&gt;
                      &lt;/includes&gt;
                  &lt;/resource&gt;
                  &lt;resource&gt;
                      &lt;directory&gt;${project.basedir}/src/main/resources&lt;/directory&gt;
                      &lt;includes&gt;
                          &lt;include&gt;**/*.xml&lt;/include&gt;
                          &lt;include&gt;**/*.properties&lt;/include&gt;
                          &lt;include&gt;profiles/*&lt;/include&gt;
                      &lt;/includes&gt;
                  &lt;/resource&gt;
              &lt;/resources&gt;
          &lt;/build&gt;
      &lt;/profile&gt;
  &lt;/profiles&gt;
  </code></pre>