Search code examples
javaspringspring-bootflyway

Flyway in common library that has integration tests


I'm running into a silly situation where I have my flyway dependency defined in a common library's pom file. This common library happens to have Spring Boot integration tests that load the context and so when those integration tests run I get

java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)

I'd rather not duplicate the dependency definition in all of the applications' poms and I can't remove the integration tests. I'd also rather not have a dummy migrations folder. Can I just turn this off somehow in the integration tests?

@SpringBootTest
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@DisableFlywaySomehow
public class MyITest {...}

Solution

  • Use a different profile (although you can also use your current test profile) and just set spring.flyway.enabled = false in your application.{properties,yml} file.

    You can also play with the @TestPropertySource annotation on a test-by-test case.