Package io.github.suppierk.codegen
Class FlywayMigrateTask
java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
io.github.suppierk.codegen.FlywayMigrateTask
- All Implemented Interfaces:
Comparable<org.gradle.api.Task>,org.gradle.api.internal.DynamicObjectAware,org.gradle.api.internal.TaskInternal,org.gradle.api.Named,org.gradle.api.plugins.ExtensionAware,org.gradle.api.Task,org.gradle.util.Configurable<org.gradle.api.Task>
public class FlywayMigrateTask
extends org.gradle.api.DefaultTask
Task that runs Flyway migrations inside a temporary Testcontainers database without invoking
jOOQ. Useful for developers who want to validate migrations without generating sources.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.gradle.api.Task
org.gradle.api.Task.Namer -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DatabaseExtensionDatabase definition supplying container overrides and driver selection.protected StringName of the logical database currently processed (if provided by the DSL).protected static final StringFallback Flyway location used when no migration locations are defined.protected final FlywayConfigFlyway configuration provided by the schema DSL.protected final nu.studer.gradle.jooq.JooqConfigjOOQ configuration currently being processed.protected StringOptional driver override supplied by the DSL.protected StringName of the schema currently processed (if provided by the DSL).Fields inherited from interface org.gradle.api.Task
TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE -
Constructor Summary
ConstructorsConstructorDescriptionFlywayMigrateTask(DatabaseExtension databaseExtension, FlywayConfig flywayConfig, nu.studer.gradle.jooq.JooqConfig jooqConfig) Creates a new Flyway-only task bound to the provided jOOQ configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyDslOverrides(String databaseName, String schemaName, String driverClassName) Applies schema metadata captured from the DSL.Gathers the runtime classpath entries that should back Flyway execution.protected final URLClassLoaderCreates a dedicated class loader containing the runtime classpath needed for Flyway execution.static StringcreateTaskName(nu.studer.gradle.jooq.JooqConfig jooqConfig) Derives a predictable task name from the supplied jOOQ configuration.protected final voidensureDriverAvailable(String driverClassName, ClassLoader fallbackLoader) Ensures the supplied driver class can be resolved via either the current context class loader or the provided fallback.org.gradle.api.file.ConfigurableFileCollectionRuntime classpath Gradle should fingerprint to detect Flyway code changes.protected final BooleanresolveBoolean(Function<FlywayConfig, Boolean> getter) Resolves a boolean property from schema overrides or the base Flyway configuration.protected final StringresolveDriver(String fallbackDriver) Resolves the JDBC driver to use, preferring DSL overrides, then Flyway defaults, and finally the existing jOOQ configuration.protected final IntegerresolveInteger(Function<FlywayConfig, Integer> getter) Resolves an integer property from schema overrides or the base Flyway configuration.resolveList(Function<FlywayConfig, List<String>> getter) Resolves a list property from schema overrides or the base Flyway configuration.resolveMap(Function<FlywayConfig, Map<String, String>> getter) Resolves a map property from schema overrides or the base Flyway configuration.protected final StringresolveSchema(String fallbackSchema) Resolves the schema to target, preferring DSL overrides, then Flyway defaults, and finally the existing jOOQ configuration.protected final StringresolveString(Function<FlywayConfig, String> getter) Resolves a string property from schema overrides or the base Flyway configuration.voidrun()Runs Flyway migrations against the configured container using the same driver resolution logic asGeneratorTask, but without invoking jOOQ.protected final voidrunFlywayMigrations(AbstractDatabaseContainer db, String schema) Runs Flyway migrations using a container supplied by the extension.protected final voidrunFlywayMigrations(AbstractDatabaseContainer db, String schema, URLClassLoader classLoader) Runs Flyway migrations using a dedicated class loader.protected final voidwithDatabase(String driverClassName, io.github.suppierk.codegen.AbstractDatabaseTask.DatabaseAction action) Executes the supplied action with a managed database container and dedicated class loader.Methods inherited from class org.gradle.api.DefaultTask
compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesServiceMethods inherited from class org.gradle.api.internal.AbstractTask
acceptServiceReferences, appendParallelSafeAction, doNotTrackState, getAsDynamicObject, getConvention, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, setImpliesSubProjectsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gradle.api.Task
doNotTrackState, getConvention, notCompatibleWithConfigurationCache
-
Field Details
-
FALLBACK_FLYWAY_LOCATION
Fallback Flyway location used when no migration locations are defined.- See Also:
-
databaseExtension
Database definition supplying container overrides and driver selection. -
flywayConfig
Flyway configuration provided by the schema DSL. -
jooqConfig
@Nonnull protected final nu.studer.gradle.jooq.JooqConfig jooqConfigjOOQ configuration currently being processed. -
overrideDriverClassName
Optional driver override supplied by the DSL. -
schemaName
Name of the schema currently processed (if provided by the DSL). -
databaseName
Name of the logical database currently processed (if provided by the DSL).
-
-
Constructor Details
-
FlywayMigrateTask
@Inject public FlywayMigrateTask(@Nonnull DatabaseExtension databaseExtension, @Nonnull FlywayConfig flywayConfig, @Nonnull nu.studer.gradle.jooq.JooqConfig jooqConfig) Creates a new Flyway-only task bound to the provided jOOQ configuration.- Parameters:
databaseExtension- database specification from the DSLflywayConfig- schema-specific Flyway configurationjooqConfig- associated jOOQ configuration
-
-
Method Details
-
createTaskName
Derives a predictable task name from the supplied jOOQ configuration.- Parameters:
jooqConfig- configuration to inspect- Returns:
- Gradle task name exposing Flyway migrations for the configuration
-
run
public void run()Runs Flyway migrations against the configured container using the same driver resolution logic asGeneratorTask, but without invoking jOOQ.- See Also:
-
applyDslOverrides
public void applyDslOverrides(@Nonnull String databaseName, @Nonnull String schemaName, @Nullable String driverClassName) Applies schema metadata captured from the DSL.- Parameters:
databaseName- logical database identifier (used for diagnostics)schemaName- logical schema identifier (used for diagnostics)driverClassName- optional driver override provided by the DSL
-
getFlywayClasspath
@Classpath @Nonnull public org.gradle.api.file.ConfigurableFileCollection getFlywayClasspath()Runtime classpath Gradle should fingerprint to detect Flyway code changes.- Returns:
- file collection representing the Flyway runtime classpath
-
runFlywayMigrations
protected final void runFlywayMigrations(@Nonnull AbstractDatabaseContainer db, @Nonnull String schema) Runs Flyway migrations using a container supplied by the extension.- Parameters:
db- database container to targetschema- schema to migrate
-
runFlywayMigrations
protected final void runFlywayMigrations(@Nonnull AbstractDatabaseContainer db, @Nonnull String schema, @Nonnull URLClassLoader classLoader) Runs Flyway migrations using a dedicated class loader.- Parameters:
db- database container to targetschema- schema to migrateclassLoader- class loader to use when resolving application classes
-
resolveSchema
Resolves the schema to target, preferring DSL overrides, then Flyway defaults, and finally the existing jOOQ configuration. Throws a detailed exception when the DSL does not identify a schema or when Flyway and jOOQ disagree.- Parameters:
fallbackSchema- schema declared in the jOOQ configuration- Returns:
- resolved schema name
-
resolveDriver
Resolves the JDBC driver to use, preferring DSL overrides, then Flyway defaults, and finally the existing jOOQ configuration. Throws a descriptive exception when no driver can be found so that users know how to amend their configuration.- Parameters:
fallbackDriver- driver declared in the jOOQ configuration- Returns:
- resolved driver class name
-
ensureDriverAvailable
protected final void ensureDriverAvailable(@Nonnull String driverClassName, @Nonnull ClassLoader fallbackLoader) Ensures the supplied driver class can be resolved via either the current context class loader or the provided fallback. Prevents confusing Testcontainers errors by verifying driver availability up front.- Parameters:
driverClassName- fully qualified JDBC driver class namefallbackLoader- class loader capable of resolving project dependencies
-
createFlywayClassLoader
Creates a dedicated class loader containing the runtime classpath needed for Flyway execution.- Returns:
- new
URLClassLoaderinstance
-
withDatabase
protected final void withDatabase(@Nonnull String driverClassName, @Nonnull io.github.suppierk.codegen.AbstractDatabaseTask.DatabaseAction action) Executes the supplied action with a managed database container and dedicated class loader.- Parameters:
driverClassName- JDBC driver class to resolveaction- callback invoked once the container is ready
-
collectFlywayClasspathEntries
Gathers the runtime classpath entries that should back Flyway execution.- Returns:
- set of files contributing to the Flyway classpath
-
resolveString
Resolves a string property from schema overrides or the base Flyway configuration.- Parameters:
getter- accessor to invoke on the configuration- Returns:
- resolved value or
null
-
resolveList
@Nonnull protected final List<String> resolveList(@Nonnull Function<FlywayConfig, List<String>> getter) Resolves a list property from schema overrides or the base Flyway configuration.- Parameters:
getter- accessor to invoke on the configuration- Returns:
- resolved list (never
null)
-
resolveMap
@Nonnull protected final Map<String,String> resolveMap(@Nonnull Function<FlywayConfig, Map<String, String>> getter) Resolves a map property from schema overrides or the base Flyway configuration.- Parameters:
getter- accessor to invoke on the configuration- Returns:
- resolved map combining overrides and defaults
-
resolveInteger
Resolves an integer property from schema overrides or the base Flyway configuration.- Parameters:
getter- accessor to invoke on the configuration- Returns:
- resolved integer or
null
-
resolveBoolean
Resolves a boolean property from schema overrides or the base Flyway configuration.- Parameters:
getter- accessor to invoke on the configuration- Returns:
- resolved boolean or
null
-