title: How to set Flyway migration file location using Spring profiles
body: <p>I have two Spring profiles <code>dev</code> and <code>test</code> configured for development and test environment. And in each environment I am using different databases viz <code>h2</code> in dev and <code>postgresql</code> in testing. Following are my properties files for each profile where <code>{vendor}</code> is resolved by spring boot to <code>h2</code> and <code>postgresql</code> repectively as per datasource configured.</p>
  
  <p>application-dev.properties</p>
  
  <pre><code>spring.flyway.locations=classpath:db/migration/{vendor}
  </code></pre>
  
  <p>application-test.properties</p>
  
  <pre><code>#Data source
  spring.datasource.url=jdbc:postgresql://localhost:5432/test
  spring.datasource.username=postgres
  spring.datasource.password=postgres
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
  
  #Flyway
  spring.flyway.check-location=false
  spring.flyway.locations=classpath:/db/migration/test/{vendor}
  </code></pre>
  
  <p>Flyway migration files for <code>dev</code> profile are under <code>test/resources</code> and for <code>test</code> profile under <code>main/resources</code></p>
  
  <p><a href="https://i.stack.imgur.com/QLS9e.png" rel="noreferrer"><img src="https://i.stack.imgur.com/QLS9e.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/OU6Lm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/OU6Lm.png" alt="enter image description here"></a></p>
  
  <p>This is working fine when I run my application with <code>test</code> profile where it picks migration files only under <code>main/resources</code>. However, When I run my unit test using <code>dev</code> profile. I expect it to pick files only under <code>src/test/resources/db/migration/h2</code>. But Flyway is picking up migration files from <code>main/resources</code> and <code>test/resources</code> both leading to error </p>
  
  <blockquote>
    <p>org.flywaydb.core.api.FlywayException: Found more than one migration with version 1</p>
  </blockquote>
  
  <p>I don't understand this behavior. Any inputs on how to fix this?</p>