Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property spring.autoconfigure.exclude ignored by test slices #21736

Closed
jnizet opened this issue Jun 6, 2020 · 1 comment
Closed

Property spring.autoconfigure.exclude ignored by test slices #21736

jnizet opened this issue Jun 6, 2020 · 1 comment
Labels
type: bug A general bug
Milestone

Comments

@jnizet
Copy link
Contributor

jnizet commented Jun 6, 2020

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).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 6, 2020
@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Jun 16, 2020
@wilkinsona wilkinsona changed the title Property spring.autoconfigure.exclude ignored by DataJpaTest Property spring.autoconfigure.exclude ignored by test slices Jun 17, 2020
@wilkinsona wilkinsona changed the title Property spring.autoconfigure.exclude ignored by test slices Property spring.autoconfigure.exclude ignored by test slices Jun 17, 2020
@wilkinsona wilkinsona added type: bug A general bug and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Jun 17, 2020
@wilkinsona wilkinsona added this to the 2.3.x milestone Jun 17, 2020
@wilkinsona
Copy link
Member

wilkinsona commented Jul 8, 2020

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.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Jul 8, 2020
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Jul 8, 2020
@wilkinsona wilkinsona modified the milestones: 2.3.x, 2.3.2 Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants