Skip to content

7.5. Flyway + jOOQ Codegen Integrated Build Flow

7.5.1. Build Order

┌─────────────────────────────────────────────────────────┐
│                    mvn compile                           │
└──────────────────────┬──────────────────────────────────┘


              ┌─────────────────┐
              │  flyway:migrate  │   ① Apply DB schema
              └────────┬────────┘


              ┌─────────────────┐
              │  jooq:generate   │   ② Generate Java code
              └────────┬────────┘


              ┌─────────────────┐
              │    compile       │   ③ Compile
              └─────────────────┘

7.5.2. Maven Execution Order Configuration

The plugin execution order is controlled via <phase> and <execution> ordering in pom.xml.

xml
<build>
  <plugins>
    <!-- Step 1: Flyway migration -->
    <plugin>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-maven-plugin</artifactId>
      <executions>
        <execution>
          <id>flyway-migrate</id>
          <phase>generate-sources</phase>
          <goals>
            <goal>migrate</goal>
          </goals>
        </execution>
      </executions>
      <!-- Configuration omitted (refer to the [Flyway Configuration](/en/backend/data/flyway-config) document) -->
    </plugin>

    <!-- Step 2: jOOQ code generation -->
    <plugin>
      <groupId>org.jooq</groupId>
      <artifactId>jooq-codegen-maven</artifactId>
      <executions>
        <execution>
          <id>jooq-codegen</id>
          <phase>generate-sources</phase>
          <goals>
            <goal>generate</goal>
          </goals>
        </execution>
      </executions>
      <!-- Configuration omitted (refer to the [jOOQ Code Generation](/en/backend/data/jooq-codegen) document) -->
    </plugin>
  </plugins>
</build>

7.5.3. Local Development Workflow

  1. Start PostgreSQL with Docker Compose.
  2. Write migration files (src/main/resources/db/migration/).
  3. Run mvn generate-sources to execute Flyway migration + jOOQ codegen.
  4. Write Repository code using the generated jOOQ classes.
bash
# Start PostgreSQL
docker compose up -d

# Migration + code generation
mvn generate-sources

# Run application
mvn spring-boot:run

7.5.4. CI Environment Workflow

In CI, a PostgreSQL service is required for Flyway migration and jOOQ codegen.

yaml
# .circleci/config.yml (excerpt)
backend-build:
  docker:
    - image: cimg/openjdk:21.0
    - image: cimg/postgres:16.0
      environment:
        POSTGRES_DB: flowin
        POSTGRES_USER: flowin
        POSTGRES_PASSWORD: flowin1234
  steps:
    - checkout
    - run:
        name: Wait for DB
        command: dockerize -wait tcp://localhost:5432 -timeout 60s
    - run:
        name: Build (migration + codegen + compile)
        command: mvn package

TIENIPIA QUALIFIED STANDARD