(Quick Reference)


The schema-export command uses Hibernate’s SchemaExport tool to generate Data Definition Language (DDL) or export the schema. You need to add it to the build classpath for this command to work properly.


// buildSrc/build.gradle
repositories {
    maven { url "https://repo.grails.org/grails/core/" }
dependencies {
./gradlew runCommand -Pargs="schema-export"
./gradlew runCommand -Pargs="schema-export --datasource=lookup"
./gradlew runCommand -Pargs="grails prod schema-export"
./gradlew runCommand -Pargs="grails dev schema-export"
./gradlew runCommand -Pargs="grails prod schema-export export"
./gradlew runCommand -Pargs="grails prod schema-export export --datasource=auditing"
./gradlew runCommand -Pargs="grails prod schema-export stdout"



./gradlew runCommand -Pargs="<<environment>> schema-export <<action>> ['stdout'] <<filename>> [--datasource]"


  • environment - The environment containing the database configuration to use (e.g., dev, prod).

  • action - Can be either 'generate' or 'export', with the default being 'generate'. Specifying 'export' will execute the script against the specified environment’s database instead of just generating the DDL file.

  • stdout - Including 'stdout' will cause the script to output the DDL to the standard output (stdout).

  • filename - Specifies the name of the file to write the DDL to, with the default being 'ddl.sql' in the project’s 'target' directory.

  • datasource - The DataSource name suffix; defaults to the default DataSource if not specified.