Auto-exclude Spring Boot LiquibaseAutoConfiguration when Database Migration Plugin is present#15405
Auto-exclude Spring Boot LiquibaseAutoConfiguration when Database Migration Plugin is present#15405jamesfredley wants to merge 2 commits intoapache:7.0.xfrom
Conversation
…ration Plugin is present
|
There's already a built in way to exclude problematic autoconfiguration via the Application AST transform. Since there's a way to do this already, shoudln't we adopt the "grails way"? |
|
Wait, I just looked at the referenced spring security config - this PR makes it sound like we agreed on this approach and this PR is just following that approach. But that approach doesn't appear to be existing; it's new via https://github.com/apache/grails-spring-security/pull/1205/changes As an optional, external plugin I understand that it needs to implement the exclusion logic, but we've approached the Grails autoconfiguration exclusion differently in core. We need to decide on one way and not adopt multiple ways. ApplicationClassInjector is the class that has built in excludes. The database plugin should be added here if it's present on the classpath. @matrei what are your thoughts? |
|
The readme is where the spring security config suggestion currently lives: https://github.com/apache/grails-spring-security/blame/7.0.x/README.md#L52. https://github.com/apache/grails-spring-security/pull/1205/changes suggests making it automatic instead of manual. |
|
@jdaugherty I agree this works, it just feels a bit odd doing it in grails-core for an optional (although often used) plugin |
|
I think ti's reasonable for anything in core to use the core accepted solution. For independent projects, it doesn't make sense to make the change in core. I just mostly want to have 1 way of doing this instead of multiple in grails-core. |
|
Ok, I will switch it out. |
Replace the runtime AutoConfigurationImportFilter approach with a compile-time AST transformation in ApplicationClassInjector. When DatabaseMigrationGrailsPlugin is on the classpath, the exclusion is added to @EnableAutoConfiguration(excludeName=...) during compilation - the same mechanism already used for DataSourceAutoConfiguration, ReactorAutoConfiguration, and HibernateJpaAutoConfiguration. Opt-out via system property in gradle.properties: systemProp.grails.dbmigration.excludeLiquibaseAutoConfiguration=false Assisted-by: Claude Code <Claude@Claude.ai>
Summary
Automatically excludes Spring Boot's
LiquibaseAutoConfigurationwhen the Database Migration Plugin is on the classpath, using Grails' existing AST transformation inApplicationClassInjector. This eliminates the need for users to manually addspring.liquibase.enabled: falseto their configuration.Bug Description
When a Grails application uses the Database Migration Plugin, Spring Boot's
LiquibaseAutoConfigurationcreates its ownSpringLiquibasebean that conflicts with the plugin's own Liquibase lifecycle management inDatabaseMigrationGrailsPlugin.doWithApplicationContext(). This causes:DATABASECHANGELOGLOCKUsers must currently add this workaround to
application.yml:Fix
Added a conditional exclusion to
ApplicationClassInjector- the same AST transformation that already excludesDataSourceAutoConfiguration,ReactorAutoConfiguration, andHibernateJpaAutoConfiguration. WhenDatabaseMigrationGrailsPluginis detected on the classpath viaClassUtils.isPresent(),LiquibaseAutoConfigurationis added to@EnableAutoConfiguration(excludeName=...)at compile time.This is a single-mechanism approach that hooks into existing Grails infrastructure rather than adding new runtime components.
Opt-out
To disable the automatic exclusion, add the following to your project's
gradle.properties:systemProp.grails.dbmigration.excludeLiquibaseAutoConfiguration=falseThis system property is read at compile time during the AST transformation. When set to
false, the exclusion is not added and Spring Boot's Liquibase auto-configuration will run alongside the plugin.Files Changed
grails-core/.../ApplicationClassInjector.groovy- AddedCONDITIONAL_EXCLUSIONSlist and conditional exclusion logic with system property opt-outgrails-core/.../ApplicationClassInjectorSpec.groovy- 6 new Spock testsgrails-doc/.../automaticDatabaseMigration.adoc- Documentation for the auto-exclusion and opt-outgrails-data-hibernate5/dbmigration/README.md- Documentation for the auto-exclusion and opt-outTest Coverage
All 6 tests pass:
Example Application
https://github.com/jamesfredley/grails-liquibase-autoconfig-conflict
Environment Information