jamesfredley opened a new pull request, #15405:
URL: https://github.com/apache/grails-core/pull/15405
## Summary
Adds an `AutoConfigurationImportFilter` to the Grails Database Migration
Plugin that automatically excludes Spring Boot's `LiquibaseAutoConfiguration`
when the plugin is on the classpath, eliminating the need for users to manually
add `spring.liquibase.enabled: false` to their configuration.
## Bug Description
When a Grails application uses the Database Migration Plugin
(`grails-data-hibernate5-dbmigration`), Spring Boot's
`LiquibaseAutoConfiguration` creates its own `SpringLiquibase` bean that
conflicts with the plugin's own Liquibase lifecycle management in
`DatabaseMigrationGrailsPlugin.doWithApplicationContext()`. This causes:
- Duplicate changelog execution attempts
- Lock contention on `DATABASECHANGELOGLOCK`
- Startup failures or unexpected behavior
Users must currently add this workaround to `application.yml`:
```yaml
spring:
liquibase:
enabled: false
```
This is a common pitfall that every Grails project using the Database
Migration Plugin encounters.
## Root Cause
`DatabaseMigrationGrailsPlugin` manages Liquibase entirely through its own
lifecycle (`doWithSpring` + `doWithApplicationContext`), but does not exclude
Spring Boot's `LiquibaseAutoConfiguration`. Both systems attempt to initialize
Liquibase independently.
## Fix
Added `LiquibaseAutoConfigurationExcluder` - an
`AutoConfigurationImportFilter` registered via `META-INF/spring.factories`.
This filter runs during Spring Boot's auto-configuration discovery phase
(before any auto-configuration bytecode is loaded) and excludes
`org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration`.
This follows the exact same pattern used in PR #1205 for
grails-spring-security (`SecurityAutoConfigurationExcluder`).
**Backwards compatibility**: This change is fully backwards compatible.
Projects that already have `spring.liquibase.enabled: false` will see no change
in behavior - the auto-configuration is now excluded before the property is
even evaluated. Projects without the workaround will now work correctly without
it.
## Files Changed
-
`grails-data-hibernate5/dbmigration/src/main/groovy/.../LiquibaseAutoConfigurationExcluder.groovy`
- New `AutoConfigurationImportFilter` implementation
-
`grails-data-hibernate5/dbmigration/src/main/resources/META-INF/spring.factories`
- Registers the filter
-
`grails-data-hibernate5/dbmigration/src/test/groovy/.../LiquibaseAutoConfigurationExcluderSpec.groovy`
- 7 Spock tests
## Test Coverage
All 7 tests pass:
| Test | Verifies |
|------|----------|
| `excludes LiquibaseAutoConfiguration` | Target class excluded, others
allowed |
| `allows all non-Liquibase auto-configurations` | No false positives |
| `handles empty candidate list` | Edge case - empty array |
| `handles null entries in candidate list` | Edge case - null entries |
| `excluded set contains exactly LiquibaseAutoConfiguration` | Correct
exclusion set |
| `excluded set is unmodifiable` | Defensive copy |
| `registered in spring.factories as AutoConfigurationImportFilter` |
`SpringFactoriesLoader` discovers the filter |
## Example Application
https://github.com/jamesfredley/grails-liquibase-autoconfig-conflict
A minimal Grails 7 app with the Database Migration Plugin configured.
Without the fix, `curl http://localhost:8080/bugDemo/index` returns `{
"bug_present": true }` (detecting that `LiquibaseAutoConfiguration` is loaded
alongside the plugin). With the fix applied, the auto-configuration is excluded
and the plugin manages Liquibase exclusively.
## Environment Information
- Grails: 7.0.7
- Spring Boot: 3.5.10
- Groovy: 4.0.30
- Liquibase: 4.27.0 (managed by BOM)
- JDK: 25
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]