title: maven profile overwrites test resources
body: <p>I'm trying to make maven profiles which would use two difference DBMS. DBMS configs are stored in maven profiles. Web App gets settings from file connection.properties in src/main/resources. There is also a similar file with same title connection.properties in src/test/resources and this file should be uploaded only during test lyfecycle maven. Then spring core uses the DBMS connection settings specified in connection.properties.</p>
  
  <p>I have problem with maven profile which overwrites resources such as src/test/resources/connection.properties on src/main/resources/connection.properties from test directory when test lifecycle maven is running.</p>
  
  <pre><code>&lt;profile&gt;
          &lt;id&gt;profile-postgres&lt;/id&gt;
          &lt;activation&gt;
              &lt;activeByDefault&gt;true&lt;/activeByDefault&gt;
          &lt;/activation&gt;
          &lt;properties&gt;
              &lt;database.driver_class_name&gt;org.postgresql.Driver&lt;/database.driver_class_name&gt;
              &lt;database.url&gt;jdbc:postgresql://127.0.0.1:5432/bulls_and_cows&lt;/database.url&gt;
              &lt;database.username&gt;postgres&lt;/database.username&gt;
              &lt;database.password&gt;postgres&lt;/database.password&gt;
  
              &lt;jpa.show_sql&gt;true&lt;/jpa.show_sql&gt;
              &lt;jpa.generate_ddl&gt;true&lt;/jpa.generate_ddl&gt;
              &lt;jpa.database&gt;POSTGRESQL&lt;/jpa.database&gt;
              &lt;jpa.database_platform&gt;org.hibernate.dialect.PostgreSQL95Dialect&lt;/jpa.database_platform&gt;
              &lt;jpa.hibernate.hbm2ddl.auto&gt;validate&lt;/jpa.hibernate.hbm2ddl.auto&gt;
              &lt;jpa.hibernate.format_sql&gt;false&lt;/jpa.hibernate.format_sql&gt;
  
              &lt;h2.scope&gt;test&lt;/h2.scope&gt;
          &lt;dependencies&gt;
              &lt;!-- https://mvnrepository.com/artifact/org.postgresql/postgresql --&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
                  &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
                  &lt;version&gt;42.2.1&lt;/version&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
          &lt;/properties&gt;
      &lt;/profile&gt;
      &lt;profile&gt;
              &lt;id&gt;profile-h2&lt;/id&gt;
              &lt;activation&gt;
                  &lt;activeByDefault&gt;false&lt;/activeByDefault&gt;
              &lt;/activation&gt;
              &lt;properties&gt;
                  &lt;database.driver_class_name&gt;org.h2.Driver&lt;/database.driver_class_name&gt;
                  &lt;database.url&gt;jdbc:h2:mem:h2db;DB_CLOSE_DELAY=-1&lt;/database.url&gt;
                  &lt;database.username&gt;sa&lt;/database.username&gt;
                  &lt;database.password&gt;sa&lt;/database.password&gt;
  
                  &lt;jpa.show_sql&gt;true&lt;/jpa.show_sql&gt;
                  &lt;jpa.generate_ddl&gt;true&lt;/jpa.generate_ddl&gt;
                  &lt;jpa.database&gt;H2&lt;/jpa.database&gt;
                  &lt;jpa.database_platform&gt;org.hibernate.dialect.H2Dialect&lt;/jpa.database_platform&gt;
                  &lt;jpa.hibernate.hbm2ddl.auto&gt;create-drop&lt;/jpa.hibernate.hbm2ddl.auto&gt;
                  &lt;jpa.hibernate.format_sql&gt;false&lt;/jpa.hibernate.format_sql&gt;
  
                  &lt;h2.scope&gt;compile&lt;/h2.scope&gt;
              &lt;/properties&gt;
          &lt;/profile&gt;
  &lt;/profiles&gt;
  </code></pre>
  
  <p>This profile overwrites my connection.properties from src/test/resources on src/main/resources.</p>
  
  <p>connection.properties from src/test/resources</p>
  
  <pre><code>database.driver_class_name=org.h2.Driver
  database.url=jdbc:h2:mem:h2db;DB_CLOSE_DELAY=-1
  database.username=sa
  database.password=sa
  </code></pre>
  
  <p>connection.properties from src/main/resources</p>
  
  <pre><code>database.driver_class_name=${database.driver_class_name}
  database.url=${database.url}
  database.username=${database.username}
  database.password=${database.password}
  </code></pre>
  
  <p>I wrote testResources tag in build tag of root pom file and in build tag of profile tag such as</p>
  
  <pre><code>&lt;testResources&gt;
      &lt;testResource&gt;
          &lt;directory&gt;${project.basedir}/src/test/resources&lt;/directory&gt;
          &lt;filtering&gt;true&lt;/filtering&gt;
      &lt;/testResource&gt;
  &lt;/testResources&gt;
  </code></pre>
  
  <p>But instead connection.properties from src/main/resources was always used in test lifecycle of maven.</p>
  
  <p>My old failed build where I used profiles from <a href="https://travis-ci.org/WeDism/BullsAndCows/builds/449051809" rel="nofollow noreferrer">https://travis-ci.org/WeDism/BullsAndCows/builds/449051809</a>.</p>
  
  <p>My repo with master branch <a href="https://github.com/WeDism/BullsAndCows/blob/master/pom.xml" rel="nofollow noreferrer">https://github.com/WeDism/BullsAndCows/blob/master/pom.xml</a>.</p>
  
  <p>My repo with with_profiles_h2_postgres branch <a href="https://github.com/WeDism/BullsAndCows/blob/with_profiles_h2_postgres/pom.xml" rel="nofollow noreferrer">https://github.com/WeDism/BullsAndCows/blob/with_profiles_h2_postgres/pom.xml</a></p>
  
  <p>Profile profile-postgres should be main such as activeByDefault = true</p>