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:
  • GeneratorTask
  • AbstractDatabaseTask.runFlywayMigrations(io.github.suppierk.codegen.docker.AbstractDatabaseContainer, String, java.net.URLClassLoader)
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.gradle.api.Task

    org.gradle.api.Task.Namer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final DatabaseExtension
    Database definition supplying container overrides and driver selection.
    protected String
    Name of the logical database currently processed (if provided by the DSL).
    protected static final String
    Fallback Flyway location used when no migration locations are defined.
    protected final FlywayConfig
    Flyway configuration provided by the schema DSL.
    protected final nu.studer.gradle.jooq.JooqConfig
    jOOQ configuration currently being processed.
    protected String
    Optional driver override supplied by the DSL.
    protected String
    Name 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

    Constructors
    Constructor
    Description
    FlywayMigrateTask(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 Type
    Method
    Description
    void
    applyDslOverrides(String databaseName, String schemaName, String driverClassName)
    Applies schema metadata captured from the DSL.
    protected final Set<File>
    Gathers the runtime classpath entries that should back Flyway execution.
    protected final URLClassLoader
    Creates a dedicated class loader containing the runtime classpath needed for Flyway execution.
    static String
    createTaskName(nu.studer.gradle.jooq.JooqConfig jooqConfig)
    Derives a predictable task name from the supplied jOOQ configuration.
    protected final void
    ensureDriverAvailable(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.ConfigurableFileCollection
    Runtime classpath Gradle should fingerprint to detect Flyway code changes.
    protected final Boolean
    Resolves a boolean property from schema overrides or the base Flyway configuration.
    protected final String
    resolveDriver(String fallbackDriver)
    Resolves the JDBC driver to use, preferring DSL overrides, then Flyway defaults, and finally the existing jOOQ configuration.
    protected final Integer
    Resolves an integer property from schema overrides or the base Flyway configuration.
    protected final List<String>
    Resolves a list property from schema overrides or the base Flyway configuration.
    protected final Map<String,String>
    Resolves a map property from schema overrides or the base Flyway configuration.
    protected final String
    resolveSchema(String fallbackSchema)
    Resolves the schema to target, preferring DSL overrides, then Flyway defaults, and finally the existing jOOQ configuration.
    protected final String
    Resolves a string property from schema overrides or the base Flyway configuration.
    void
    run()
    Runs Flyway migrations against the configured container using the same driver resolution logic as GeneratorTask, but without invoking jOOQ.
    protected final void
    Runs Flyway migrations using a container supplied by the extension.
    protected final void
    Runs Flyway migrations using a dedicated class loader.
    protected final void
    withDatabase(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, usesService

    Methods 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, setImpliesSubProjects

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.gradle.api.Task

    doNotTrackState, getConvention, notCompatibleWithConfigurationCache
  • Field Details

    • FALLBACK_FLYWAY_LOCATION

      protected static final String FALLBACK_FLYWAY_LOCATION
      Fallback Flyway location used when no migration locations are defined.
      See Also:
    • databaseExtension

      @Nonnull protected final DatabaseExtension databaseExtension
      Database definition supplying container overrides and driver selection.
    • flywayConfig

      @Nonnull protected final FlywayConfig flywayConfig
      Flyway configuration provided by the schema DSL.
    • jooqConfig

      @Nonnull protected final nu.studer.gradle.jooq.JooqConfig jooqConfig
      jOOQ configuration currently being processed.
    • overrideDriverClassName

      @Nullable protected String overrideDriverClassName
      Optional driver override supplied by the DSL.
    • schemaName

      @Nullable protected String schemaName
      Name of the schema currently processed (if provided by the DSL).
    • databaseName

      @Nullable protected String 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 DSL
      flywayConfig - schema-specific Flyway configuration
      jooqConfig - associated jOOQ configuration
  • Method Details

    • createTaskName

      @Nonnull public static String createTaskName(@Nonnull nu.studer.gradle.jooq.JooqConfig jooqConfig)
      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 as GeneratorTask, 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 target
      schema - 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 target
      schema - schema to migrate
      classLoader - class loader to use when resolving application classes
    • resolveSchema

      @Nonnull protected final String resolveSchema(@Nullable String fallbackSchema)
      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

      @Nonnull protected final String resolveDriver(@Nullable String fallbackDriver)
      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 name
      fallbackLoader - class loader capable of resolving project dependencies
    • createFlywayClassLoader

      @Nonnull protected final URLClassLoader createFlywayClassLoader()
      Creates a dedicated class loader containing the runtime classpath needed for Flyway execution.
      Returns:
      new URLClassLoader instance
    • 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 resolve
      action - callback invoked once the container is ready
    • collectFlywayClasspathEntries

      @Nonnull protected final Set<File> collectFlywayClasspathEntries()
      Gathers the runtime classpath entries that should back Flyway execution.
      Returns:
      set of files contributing to the Flyway classpath
    • resolveString

      @Nullable protected final String resolveString(@Nonnull Function<FlywayConfig,String> getter)
      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

      @Nullable protected final Integer resolveInteger(@Nonnull Function<FlywayConfig,Integer> getter)
      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

      @Nullable protected final Boolean resolveBoolean(@Nonnull Function<FlywayConfig,Boolean> getter)
      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