Thanks for the pointer. I had a look at how that works and implemented a solution based on it. I’ve sent a pull request (https://github.com/liquibase/liquibase/pull/562) but I’m using a subclassing approach in the mean time:
public class SpringLiquibase extends liquibase.integration.spring.SpringLiquibase {
private boolean validateOnly = false;
public boolean isValidateOnly() {
return validateOnly;
}
public void setValidateOnly(boolean validateOnly) {
this.validateOnly = validateOnly;
}
@Override
public void afterPropertiesSet() throws LiquibaseException {
ConfigurationProperty shouldRunProperty = LiquibaseConfiguration.getInstance()
.getProperty(GlobalConfiguration.class, GlobalConfiguration.SHOULD_RUN);
if (!shouldRunProperty.getValue(Boolean.class)) {
LogFactory.getLogger()
.info("Liquibase did not run because "
+ LiquibaseConfiguration.getInstance().describeValueLookupLogic(shouldRunProperty)
+ " was set to false");
return;
}
if (!shouldRun) {
LogFactory.getLogger().info("Liquibase did not run because 'shouldRun' " + "property was set to false on "
+ getBeanName() + " Liquibase Spring bean.");
return;
}
if (validateOnly) {
Connection c = null;
Liquibase liquibase = null;
try {
c = getDataSource().getConnection();
liquibase = createLiquibase(c);
if (liquibase.listUnrunChangeSets(new Contexts(contexts), new LabelExpression(getLabels()))
.size() > 0) {
throw new LiquibaseException("Unrun changes found in validate only mode");
}
} catch (SQLException e) {
throw new DatabaseException(e);
} finally {
Database database = null;
if (liquibase != null) {
database = liquibase.getDatabase();
}
if (database != null) {
database.close();
}
}
} else {
super.afterPropertiesSet();
}
}
}