Created
February 16, 2016 11:40
-
-
Save ieugen/5fa583f7e2b66f2b0379 to your computer and use it in GitHub Desktop.
querydsl sql integration with flyway database migration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id "org.flywaydb.flyway" version "3.2.1" | |
id 'java' | |
id 'idea' | |
} | |
description = 'GR8PI :: Database Model' | |
sourceCompatibility = 1.8 | |
configurations { | |
querydslsql | |
} | |
def queryDslGenerated = "${project.projectDir}/src/main/generated" | |
sourceSets { | |
generated { | |
java.srcDir queryDslGenerated | |
} | |
} | |
dependencies { | |
compile "com.querydsl:querydsl-sql:$queryDslVersion" | |
compile "org.postgresql:postgresql:${postgresqlVersion}" | |
compile sourceSets.generated.output | |
generatedCompile "com.querydsl:querydsl-sql:$queryDslVersion" | |
querydslsql "com.querydsl:querydsl-sql:$queryDslVersion" | |
querydslsql "com.querydsl:querydsl-sql-codegen:$queryDslVersion" | |
querydslsql "org.postgresql:postgresql:${postgresqlVersion}" | |
querydslsql "org.slf4j:slf4j-simple:${slf4jVersion}" | |
testCompile group: 'junit', name: 'junit', version: '4.11' | |
} | |
def itestDb = [ | |
driver : 'org.postgresql.Driver', | |
url : 'jdbc:postgresql://127.0.0.1/itest', | |
user : 'itest', | |
password: 'itest' | |
] | |
flyway { | |
driver = itestDb.driver | |
url = itestDb.url | |
user = itestDb.user | |
password = itestDb.password | |
baselineOnMigrate = true | |
baselineVersion = '1.0.0' | |
baselineDescription = "Let's go!" | |
locations = ['filesystem:sql'] | |
} | |
task generateQueryDSLFromDB(dependsOn: ['flywayClean', 'flywayMigrate']) { | |
inputs.dir "$project.rootDir/sql" | |
outputs.dir queryDslGenerated | |
doLast { | |
ant.taskdef( | |
name: 'generateQueryDSL', | |
classname: 'com.querydsl.sql.codegen.ant.AntMetaDataExporter', | |
classpath: configurations.querydslsql.asPath) | |
ant.generateQueryDSL( | |
jdbcDriver: "$itestDb.driver", | |
jdbcUrl: "$itestDb.url", | |
jdbcUser: "$itestDb.user", | |
jdbcPassword: "$itestDb.password", | |
packageName: 'gr8pi.platform.sql', | |
exportBeans: true, | |
beanPackageName: 'gr8pi.platform.sql.beans', | |
targetFolder: queryDslGenerated) | |
} | |
} | |
compileGeneratedJava.dependsOn generateQueryDSLFromDB | |
clean { | |
delete sourceSets.generated.java.srcDirs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment