Skip to content

Commit

Permalink
feat: jooq generator plugin
Browse files Browse the repository at this point in the history
Extracted from Optravis platform-lib
  • Loading branch information
jcornaz committed Jun 17, 2024
0 parents commit aab4e4c
Show file tree
Hide file tree
Showing 22 changed files with 910 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
titleOnly: true
66 changes: 66 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: build

on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

env:
GRADLE_OPTS: "-Dorg.gradle.workers.max=2 -Dorg.gradle.console=plain"

jobs:
# Verifies all tests pass
verify:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 17
cache: gradle
- uses: taiki-e/install-action@v2
with:
tool: just@1
- run: just verify

# Prepare a release PR or release
release:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
released: ${{ steps.release.outputs.release_created }}
steps:
- id: release
uses: googleapis/release-please-action@v4
with:
release-type: simple

# Publish the artifacts (only if `verify` passed, and `release` created release)
publish:
needs: [ verify, release ]
if: needs.verify.result == 'success' && needs.release.outputs.released
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 17
cache: gradle
- uses: taiki-e/install-action@v2
with:
tool: just@1
- run: just publish
env:
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_TOKEN: ${{ github.token }}
19 changes: 19 additions & 0 deletions .github/workflows/dependency_submission.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Dependency Submission

on:
push:
branches: [ main ]

permissions:
contents: write

jobs:
dependency-submission:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: 17
- uses: gradle/actions/dependency-submission@v3
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gradle/
.idea/
.kotlin/
build/
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @Optravis-LLC/saas-platform
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Jooq generator plugin

An opinionated gradle plugin generate jOOQ classes from Flyway migrations.

The goal is to be very easy to set up jOOQ generation for projects using Kotlin, flyway and postgres.

The minimal setup for projects using Postgres (and the default flyway migration directory) is:

```kotlin
plugins {
kotlin("jvm") version "<kotlin version>" // The Kotlin plugin is required
id("com.optravis.platform.jooq") version "<platformlib version>" // Install the gradle plugin
}
```

It is possible to use other databases by configuring the (experimental) 'JooqGeneratorExtension'

```kotlin
@OptIn(ExperimentalJooqGeneratorConfig::class)
configure<JooqGeneratorExtension> {
//...
}
```
59 changes: 59 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.detekt)
`java-gradle-plugin`
}

group = "com.optravis.jooq.gradle"


repositories {
mavenCentral()
}

dependencies {
implementation(gradleKotlinDsl())
implementation(libs.jooq.codegen)
implementation(libs.flyway.core)
implementation(libs.testcontainers.core)
implementation(libs.hikari)

runtimeOnly(libs.jooq.meta.kotlin)
runtimeOnly(libs.flyway.postgres)
runtimeOnly(libs.postgresql)

testImplementation(rootProject.libs.kotest.runner)
testImplementation(rootProject.libs.kotest.assertions)
}

gradlePlugin {
plugins {
create("jooqGenerator") {
id = "com.optravis.jooq.gradle"
implementationClass = "com.optravis.jooq.gradle.JooqGeneratorPlugin"
}
}
}

java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_17
}

kotlin {
explicitApi()
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}

detekt {
config.setFrom(rootDir.resolve("detekt.yml"))
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
15 changes: 15 additions & 0 deletions detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
config:
validation: true
warningsAsErrors: true

style:
ReturnCount:
active: false
ThrowsCount:
active: false
MaxLineLength:
excludeCommentStatements: true

exceptions:
TooGenericExceptionCaught:
active: false
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configuration-cache=true
org.gradle.caching=true
40 changes: 40 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[versions]
kotlin = "2.0.0"
detekt = "1.23.6"
kotest = "5.9.1"
flyway = "10.15.0"
jooq = "3.19.10"
testcontainers = "1.19.8"
postgres = "42.7.3"
hikari = "5.1.0"

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
jooq = { id = "org.jooq.jooq-codegen-gradle", version.ref = "jooq" }

[libraries]
# jOOQ
jooq-core = { module = "org.jooq:jooq", version.ref = "jooq" }
jooq-kotlin = { module = "org.jooq:jooq-kotlin", version.ref = "jooq" }
jooq-coroutines = { module = "org.jooq:jooq-kotlin-coroutines", version.ref = "jooq" }
jooq-meta-core = { module = "org.jooq:jooq-meta", version.ref = "jooq" }
jooq-meta-kotlin = { module = "org.jooq:jooq-meta-kotlin", version.ref = "jooq" }
jooq-codegen = { module = "org.jooq:jooq-codegen", version.ref = "jooq" }

# Flyway
flyway-core = { module = "org.flywaydb:flyway-core", version.ref = "flyway" }
flyway-postgres = { module = "org.flywaydb:flyway-database-postgresql", version.ref = "flyway" }

# Test Containers
testcontainers-core = { module = "org.testcontainers:testcontainers", version.ref = "testcontainers" }
testcontainers-postgresql = { module = "org.testcontainers:postgresql", version.ref = "testcontainers" }

# DB access
postgresql = { module = "org.postgresql:postgresql", version.ref = "postgres" }
hikari = { module = "com.zaxxer:HikariCP", version.ref = "hikari" }

# Test
kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
kotest-datatest = { module = "io.kotest:kotest-framework-datatest", version.ref = "kotest" }
kotest-runner = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit aab4e4c

Please # to comment.