Skip to content

Commit

Permalink
Enhancement: Add jOOQ codegen during build
Browse files Browse the repository at this point in the history
  • Loading branch information
schnapster committed Apr 10, 2019
1 parent 158a852 commit 7423938
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -103,6 +103,7 @@ hs_err_pid*
/build/
/common/build
/discord-wrapper/build
/database-codegen/build

# Ignore Gradle GUI config
gradle-app.setting
Expand Down
5 changes: 5 additions & 0 deletions .travis.yml
Expand Up @@ -4,6 +4,7 @@ services:
- docker

addons:
postgresql: "10"
sonarcloud:
organization: "napstr-github"

Expand All @@ -14,6 +15,7 @@ env:
- secure: "TibOvGlMn0dBK97rMpvHtk17iEQszuZJkL6rqc8FoKOmMb36CFdHK7lGUCGHEoYwCl2Cs4OSICWyLhmYwfP623vYLrXfd5fdBbHWaSO1RtQkGK9+roomb80tkYleKBUArWrteYk+uevWA7HxWoQXmoVKD/DvppF6tZsJq2sv8BFQZSE2XDtiQ5QvotD0j4ypSwatZFT73AAGJlxbT3fBrx5gNw6bLJd8ZEdjRTEL+bHPAh+iqURVg3181RcEJQA3N+uAn2dkdByn4TENBLvsr4HuQmkeG0W7yTWIhZZS+t2sbp4i2PrGmEVaGeqc4DqqVSAR522NLOzwfpxXJcRr9xmfQXnt2qPyfK7cZQET/QuRvUIBw1IQo42Bae2Kk0Xhvm45FSOmgYY1YyFNFhdaK/pCbHd5jmp6djTeajeiEaH7Th6LBcDfTrNK8dmL2THvSxsodH2FRwlks+9t3KY7ZwwxXbpwbPb95qYpR8bDqlf9aIE5awNf6LXTi4l97mMNeLoN9e9yXtmDUdjPGkqZqi1nTdFfJH1Qx3RNwufFRVoIfJ7wNQG1W14hTaw6JGXCbEyJkQ5cHFzSW0T+7KH53IicnXbLDneenViDuw21vBwgT+53aHENhgwR5ZpdbhIyUVdGPvxF8udmp2NCmW3ePJrVKwWHKjj+F9I+5g4F49I="
- DOCKER_USERNAME: napstr
- secure: "RFvBcJzgPu2wvPuhxAgYNowqD4UsbgEzG06/DzWcDeRZEemnexCJr46ppL1Q7HDdYE4ftxh5H4g4O92SfNVdo0NZZGfm0E1/aHDurA40+OVML80akkwbxevU+FgXe8qofvhaF+byHgxj5m6VUAuANTV/oA3boyDbFazth8QA2+oOHLKmoTkJG0w/bBqad5q8U99rS+gwJE6tXce02X7Z4Bz7YNbl/luEJoWDVbbCv8jPoHB/RJ+OEQx3/WTKgiSjIpt70eYsjnzgW5ZJ0eWteWwwTACUX254tIUty81rkRvmPUtOEYDakVx4MeqPpsDtFmu/dffJ4ofQXkEX2cW36Y8VOPYP1dBO++iYaPZtInw2xIptIi9xCEJO1Wh1VmEK8Fb2xjFsaFzPTCVz+M0+MZxn7JuGcK1ZHN960zRkkVXP68b+YcGVUgVTJV7DyRQbhyrZY/bD/osJ695KeFx7b9SIus/FH0D2ONqp9Z5gvvA0u+Gt7ChMLY6TJTXVRThzpGOuU203cTZGysBHPfoFKMW4yR2bCFrSHG4ADw8eLFwFiYHwc0EERm8/8Cif3xvE2dTxNAONMbK0zXPGAy42D3dOt7eXT0EDQLQDQjkwGgnlv7lV8FhpEne78V8BdVr+UIUeK0IaNU0DDN/aLW52gLMlrBCYvAX7u4u7A937GYg="
- WOLFIA_CODEGEN_JDBC: "jdbc:postgresql://localhost:5432/codegen?user=postgres"

language: java

Expand All @@ -32,6 +34,9 @@ jobs:
before_script:
#for sonar cloud blame information
- git fetch --unshallow
#init codegen db
- "psql -c 'CREATE DATABASE codegen;' -U postgres"
- "psql -c 'CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA pg_catalog;' -d codegen -U postgres"
script:
- java -Xmx32m -version
- ./gradlew build --info
Expand Down
75 changes: 74 additions & 1 deletion build.gradle
Expand Up @@ -11,6 +11,8 @@ buildscript {
springBootVersion = '2.1.3.RELEASE'
sonarQubeVersion = '2.7'
bintrayVersion = '1.8.4'
flywayVersion = '5.2.4'
jooqPluginVersion = '3.0.3'

//@formatter:on
}
Expand All @@ -27,6 +29,8 @@ buildscript {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${sonarQubeVersion}"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:${bintrayVersion}"
classpath "gradle.plugin.com.boxfuse.client:gradle-plugin-publishing:${flywayVersion}"
classpath "nu.studer:gradle-jooq-plugin:${jooqPluginVersion}"
}
}

Expand Down Expand Up @@ -54,7 +58,10 @@ ext {
sqlsauceVersion = '0.4.2'
jaxbApiVersion = '2.3.1'
dsProxyVersion = '1.5.1'
flywayVersion = '5.2.4'
flywayVersion = "$flywayVersion"
jooqVersion = '3.11.11'
postgresqlVersion = '42.2.5'
javaxAnnotationsVersion = '1.3.2'

//@formatter:on

Expand Down Expand Up @@ -90,6 +97,71 @@ allprojects {
}
}

project('database-codegen') {
apply plugin: 'org.flywaydb.flyway'
apply plugin: 'nu.studer.jooq'

configurations {
flywayMigration
}

ext {
codegenJdbcUrl = System.getenv('WOLFIA_CODEGEN_JDBC') == null
? "jdbc:postgresql://localhost:5434/codegen?user=codegen"
: System.getenv('WOLFIA_CODEGEN_JDBC')
}

dependencies {
implementation "org.jooq:jooq:$jooqVersion" // object oriented sql queries
implementation "org.jooq:jooq-meta:$jooqVersion" // object oriented sql queries
implementation "org.jooq:jooq-codegen:$jooqVersion" // object oriented sql queries
// java cruft, can be removed with jooq 3.12+
implementation "javax.annotation:javax.annotation-api:$javaxAnnotationsVersion"
flywayMigration "org.postgresql:postgresql:$postgresqlVersion" // access db during codegen
jooqRuntime "org.postgresql:postgresql:$postgresqlVersion" // access db during codegen
}

flyway {
flywayMigrate.dependsOn(flywayClean)
url = "$codegenJdbcUrl"
locations = ['filesystem:database-codegen/src/main/resources/db/migrations']
configurations = ['flywayMigration']
}

jooq {
version = jooqVersion
edition = 'OSS'
wolfia(sourceSets.main) {
jdbc {
driver = 'org.postgresql.Driver'
url = "$codegenJdbcUrl"
}
generator {
name = 'org.jooq.codegen.DefaultGenerator'
strategy {
name = 'org.jooq.codegen.DefaultGeneratorStrategy'
}
database {
name = 'org.jooq.meta.postgres.PostgresDatabase'
inputSchema = 'public'
}
target {
packageName = 'space.npstr.wolfia.db.gen'
directory = 'build/classes/generated/java'
}
}
}
}

generateWolfiaJooqSchemaSource {
dependsOn(flywayMigrate)
}

test {
dependsOn(flywayMigrate)
}
}

project('discord-wrapper') {

dependencies {
Expand Down Expand Up @@ -123,6 +195,7 @@ configurations {
}

dependencies {
implementation project(':database-codegen')
implementation project(':discord-wrapper')

implementation "ch.qos.logback:logback-classic:$logbackVersion"
Expand Down
13 changes: 13 additions & 0 deletions docker/codegen/docker-compose.yaml
@@ -0,0 +1,13 @@
# Required services to run jOOQ's codegen

version: '3.7'

services:
codegen-postgres:
image: napstr/wolfia-postgres:master
restart: always
ports:
- 127.0.0.1:5434:5432
environment:
- ROLE=codegen
- DB=codegen
1 change: 1 addition & 0 deletions settings.gradle
@@ -1,4 +1,5 @@
rootProject.name = 'Wolfia'

include 'common'
include 'database-codegen'
include 'discord-wrapper'

0 comments on commit 7423938

Please sign in to comment.