If I have liquibase in the classpath, and spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration in the application.yml file, Liquibase autoconfiguration is indeed excluded when running the app, but not when executing tests annotated with @DataJpaTest.

I would have expected the exclusion to be also applicable to the tests.

The workaround is trivial: use @DataJpaTest(excludeAutoConfiguration = LiquibaseAutoConfiguration.class)

I guess that this bug could also exist for other autoconfigurations and/or other test annotations, and that changing the behavior might break lots of existing tests. So maybe the solution could simply be to better document this spring.autoconfigure.exclude property, warn that it's ignored in tests, and explain how to work around it (since it's quite easy).

Comment From: wilkinsona

Unfortunately, this is more complicated than we had realised. ImportAutoConfigurationImportSelector implements DeterminableImports which is implemented by a selector that can determine its imports early. This early determination is done before the environment has been set via EnvironmentAware. This means that the spring.autoconfigure.exclude property can't be considered and, therefore, early determination of the imports isn't possible if we want to honour that property. The imports that are determined are part of the cache key that's used by the test framework so I don't think resolving this is as simple as no longer implementing DeterminableImports.