Hello,

I have integrated following successfully:
- Liquibase with Mariadb-Testcontainer to apply DB Migrations
- Use Jooq to connect to Mariadb Test Container to generate Java Files
- using gradle
- using quarkus (but is mostly independent from quarkus)

i can share with you my example project, maybe it helps.
If you have any questions, feel free to ask :)

Example-Project:
- https://github.com/funkrusher/fk-framework-quarkus-jooq

Gradle-Build File that contains the Gradle-Task for executing a custom 
JooqCodegen-Task that starts Liquibase and does everything:
- 
https://github.com/funkrusher/fk-framework-quarkus-jooq/blob/main/_databases/fk_database1/build.gradle



debapri...@gmail.com schrieb am Mittwoch, 12. Juni 2024 um 07:57:48 UTC:

> Thank you for your prompt reply.
>
> I think the plugin 
> <https://github.com/etiennestuder/gradle-jooq-plugin#examples> 
> configuration is fine because it is working for the normal DB connection. I 
> did a few changes related to the dependencies and using mysql testcontainer 
> credentials to connect to DB.
>
> Even after I add the JDBC connection details below, still I am getting the 
> same error.
>
> /**
>  * This gradle file is used to generate JOOQ DAO, POJOs and fluent API for 
> writing SQL queries using
>  * generated classes. The default configuration below should work in most 
> cases, but it can be
>  * modified as needed based on the plugin documentation:
>  *
>  * https://github.com/etiennestuder/gradle-jooq-plugin
>  */
>
> import nu.studer.gradle.jooq.JooqGenerate
>
> buildscript {
>     repositories {
>         gradlePluginPortal()
>     }
>     dependencies {
>         classpath "nu.studer:gradle-jooq-plugin:${jooqPluginVersion}"
>     }
>     ext {
>         // use jOOQ version defined in Spring Boot
>         jooqVersion = dependencyManagement.importedProperties['jooq.version']
>     }
>     configurations.classpath {
>         // Enforce the jOOQ configuration XML schema version
>         resolutionStrategy.eachDependency {
>             if (requested.group == 'org.jooq' && 
> requested.name.startsWith('jooq')) {
>                 useVersion jooqVersion
>             }
>         }
>     }
> }
>
> apply plugin: nu.studer.gradle.jooq.JooqPlugin
>
> println("Configuring JOOQ dependencies and code generation plugin...")
>
> // JOOQ dependencies
> dependencies {
>     implementation 'org.springframework.boot:spring-boot-starter-jooq'
>     jooqGenerator 'com.mysql:mysql-connector-j'
>     jooqGenerator 'org.slf4j:slf4j-simple'
>
>     jooqGenerator 'com.fasterxml.jackson.core:jackson-databind'
>     jooqGenerator "org.testcontainers:mysql"
>     jooqGenerator 'software.aws.rds:aws-mysql-jdbc:1.+'
>
>     jooqGenerator 'org.testcontainers:jdbc'
>
> }
>
> // Configure JOOQ
> jooq {
>     version = jooqVersion
>
>     configurations {
>         main {
>             generationTool {
>                 logging = org.jooq.meta.jaxb.Logging.WARN
>                 jdbc {
>
>                     //driver = 'com.mysql.cj.jdbc.Driver'
>
>                     url = project.ext.has('dbUrl') ? project.ext.dbUrl : ''
>                     user = project.ext.has('dbUsername') ? 
> project.ext.dbUsername : ''
>                     password = project.ext.has('dbPassword') ? 
> project.ext.dbPassword : ''
>                     driver =  project.ext.has('dbDriver') ? 
> project.ext.dbDriver : ''
>                 }
>
>                 generator {
>                     name = 'org.jooq.codegen.DefaultGenerator'
>                     database {
>                         name = 'org.jooq.meta.mysql.MySQLDatabase'
>                         inputSchema = 'lmsdb'
>                     }
>                     generate {
>                         records = true
>                         immutablePojos = true
>                         fluentSetters = true
>                         javaTimeTypes = false
>                     }
>                     target {
>                         packageName = "com.chegg.${mainPackageName}.db"
>                     }
>                     strategy.name = 
> 'org.jooq.codegen.DefaultGeneratorStrategy'
>                 }
>             }
>         }
>     }
> }
>
>
> jooq.configurations.main {
>     generationTool {
>         jdbc {
>             url = project.ext.has('dbUrl') ? project.ext.dbUrl : ''
>             user = project.ext.has('dbUsername') ? project.ext.dbUsername : ''
>             password = project.ext.has('dbPassword') ? project.ext.dbPassword 
> : ''
>             driver =  project.ext.has('dbDriver') ? project.ext.dbDriver : ''
>         }
>     }
> }
>
>
> // Configure the JVM used for the JOOQ code generation process
> tasks.withType(JooqGenerate).configureEach {
>     javaExecSpec = { JavaExecSpec s ->
>         s.systemProperties System.properties
>     }
> }
>
> tasks.named('generateJooq') {
>     dependsOn ':startMySQLContainer', ':update'
>     doFirst {
>         println "Running jOOQ code generation with URL: ${project.ext.dbUrl}"
>         println "Username: ${project.ext.dbUsername}"
>         println "Password: ${project.ext.dbPassword}"
>         println "Driver: ${project.ext.dbDriver}"
>     }
> }
>
> I have no clue why that error is coming.
>
>
> Cheers,
> Debapriya Patra
> 650.933.6852 <(650)%20933-6852>
>
>
> On Wed, Jun 12, 2024 at 12:25 AM Lukas Eder <lukas...@gmail.com> wrote:
>
>> Thanks for your message.
>>
>> At a quick glance, I'd say:
>>
>> 1. The error message says: no JDBC connection configured
>> 2. You didn't correctly configure your JDBC connection
>>
>> I'm afraid I don't know gradle or the third party plugin well enough to 
>> assess whether everything is done in the right order when you do this:
>>
>> jooq {
>>     version = jooqVersion
>>
>>     configurations {
>>         main {
>>             generationTool {
>>                 logging = org.jooq.meta.jaxb.Logging.WARN
>>                 jdbc {
>>                     // No connection configured here
>>                     driver = 
>> 'org.testcontainers.jdbc.ContainerDatabaseDriver'
>>                 }
>>                 generator {
>>                     name = 'org.jooq.codegen.DefaultGenerator'
>>                     database {
>>                         name = 'org.jooq.meta.mysql.MySQLDatabase'
>>                         inputSchema = 'lmsdb'
>>                     }
>>                     generate {
>>                         records = true
>>                         immutablePojos = true
>>                         fluentSetters = true
>>                         javaTimeTypes = false
>>                     }
>>                     target {
>>                         packageName = "com.chegg.${mainPackageName}.db"
>>                     }
>>                     strategy.name = 
>> 'org.jooq.codegen.DefaultGeneratorStrategy'
>>                 }
>>             }
>>         }
>>     }
>>
>>
>>     jooq.configurations.main {
>>         generationTool {
>>             // Maybe, this happens too late?
>>             jdbc {
>>                 url = project.ext.has('dbUrl') ? project.ext.dbUrl : ''
>>                 user = project.ext.has('dbUsername') ? 
>> project.ext.dbUsername : ''
>>                 password = project.ext.has('dbPassword') ? 
>> project.ext.dbPassword : ''
>>                 driver = project.ext.has('dbDriver') ? 
>> project.ext.dbDriver : ''
>>             }
>>         }
>>     }
>>
>> On Wed, Jun 12, 2024 at 9:14 AM Debapriya Patra <debapri...@gmail.com> 
>> wrote:
>>
>>> Hi Lukas,
>>>
>>> Thank you for the reply. 
>>>
>>> After doing some modifications to my .gradle files, now I am able to 
>>> start the MySql testcontainer, apply the DB migrations using Liquibase but 
>>> when its executing the generateJooq task, its breaking with the below error.
>>> Here is the fill log when I run *./gradlew clean build* command in my 
>>> local. Any idea whats going wrong here.
>>>
>>> > Configure project :
>>> Executing build script: 
>>> https://chegg-gradle.test.devx.chegg.services/chegg-gradle/scripts/boots-build.5/application.gradle
>>> Executing build script: 
>>> https://chegg-gradle.test.devx.chegg.services/chegg-gradle/scripts/boots-build.5/internal/chegg-repository.gradle
>>> Using AWS CLI to get CodeArtifact repo URL
>>> Executing: aws codeartifact get-repository-endpoint --profile 
>>> chegg-app-edu1-nonprod --domain chegg --domain-owner 084139392869 --region 
>>> us-west-2 --repository java-chegg --format maven --query repositoryEndpoint 
>>> --output text
>>>         Result: "
>>> https://chegg-084139392869.d.codeartifact.us-west-2.amazonaws.com/maven/java-chegg/
>>> "
>>> Using repo url 
>>> https://chegg-084139392869.d.codeartifact.us-west-2.amazonaws.com/maven/java-chegg/
>>> Using AWS CLI to get CodeArtifact token
>>> Executing: aws codeartifact get-authorization-token --profile 
>>> chegg-app-edu1-nonprod --domain chegg --domain-owner 084139392869 --region 
>>> us-west-2 --query authorizationToken --output text
>>>         Result: "( 1438 hidden characters )"
>>> Executing build script: 
>>> https://chegg-gradle.test.devx.chegg.services/chegg-gradle/scripts/boots-build.5/internal/common.gradle
>>> Standard configured repositories:
>>>   - CodeArtifact (url: 
>>> https://chegg-084139392869.d.codeartifact.us-west-2.amazonaws.com/maven/java-chegg/,
>>>  
>>> username: aws)
>>>   - confluent (url: https://packages.confluent.io/maven/)
>>> Executing build script: 
>>> https://chegg-gradle.test.devx.chegg.services/chegg-gradle/scripts/boots-build.5/internal/build-props.gradle
>>> buildCheggEnv = dev
>>> Loading properties from src/main/resources/application.properties...
>>> Loading properties from src/main/resources/application-dev.properties...
>>> Found spring.application.name in application properties
>>> Loading secrets from dev/lms-registration-service...
>>> Loading parameters from /dev/lms-registration-service/...
>>> Executing build script: 
>>> https://chegg-gradle.test.devx.chegg.services/chegg-gradle/scripts/boots-build.5/internal/tests.gradle
>>> Executing build script: 
>>> https://chegg-gradle.test.devx.chegg.services/chegg-gradle/scripts/boots-build.5/internal/jacoco.gradle
>>> Executing build script: 
>>> https://chegg-gradle.test.devx.chegg.services/chegg-gradle/scripts/boots-build.5/internal/newrelic.gradle
>>> Configuring JOOQ dependencies and code generation plugin...
>>> Configuring Netflix DGS code generation plugin...
>>> ----Stating MySql DB TC----
>>>
>>> > Task :startMySQLContainer
>>> ----MySql Test container started successfully with URL : 
>>> jdbc:mysql://localhost:50255/lmsdb
>>>
>>> > Task :update
>>> liquibase-plugin: Running the 'main' activity...
>>> ####################################################
>>> ##   _     _             _ _                      ##
>>> ##  | |   (_)           (_) |                     ##
>>> ##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
>>> ##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
>>> ##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
>>> ##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
>>> ##              | |                               ##
>>> ##              |_|                               ##
>>> ##                                                ##
>>> ##  Get documentation at docs.liquibase.com       ##
>>> ##  Get certified courses at learn.liquibase.com  ##
>>> ##                                                ##
>>> ####################################################
>>> Starting Liquibase at 23:46:32 (version 4.24.0 #14062 built at 
>>> 2023-09-28 12:18+0000)
>>> [2024-06-11 23:46:32] INFO [liquibase.ui] 
>>> ####################################################
>>> ##   _     _             _ _                      ##
>>> ##  | |   (_)           (_) |                     ##
>>> ##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
>>> ##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
>>> ##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
>>> ##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
>>> ##              | |                               ##
>>> ##              |_|                               ##
>>> ##                                                ##
>>> ##  Get documentation at docs.liquibase.com       ##
>>> ##  Get certified courses at learn.liquibase.com  ##
>>> ##                                                ##
>>> ####################################################
>>> Starting Liquibase at 23:46:32 (version 4.24.0 #14062 built at 
>>> 2023-09-28 12:18+0000)
>>> Liquibase Version: 4.24.0
>>> [2024-06-11 23:46:32] INFO [liquibase.ui] Liquibase Version: 4.24.0
>>> WARNING: License service not loaded, cannot determine Liquibase Pro 
>>> license status. Please consider re-installing Liquibase to include all 
>>> dependencies. Continuing operation without Pro license.
>>> [2024-06-11 23:46:32] INFO [liquibase.ui] WARNING: License service not 
>>> loaded, cannot determine Liquibase Pro license status. Please consider 
>>> re-installing Liquibase to include all dependencies. Continuing operation 
>>> without Pro license.
>>> [2024-06-11 23:46:32] INFO [liquibase.integration] Starting command 
>>> execution.
>>> [2024-06-11 23:46:32] INFO [liquibase.changelog] Reading resource: 
>>> liquibase/db1/sqlfiles/V0__create_lms_integration_tables.sql
>>> [2024-06-11 23:46:32] INFO [liquibase.changelog] Creating database 
>>> history table with name: lmsdb.DATABASECHANGELOG
>>> [2024-06-11 23:46:32] INFO [liquibase.changelog] Reading from 
>>> lmsdb.DATABASECHANGELOG
>>> [2024-06-11 23:46:32] WARNING [liquibase.executor] Integer display width 
>>> is deprecated and will be removed in a future release.
>>> [2024-06-11 23:46:32] INFO [liquibase.lockservice] Successfully acquired 
>>> change log lock
>>> [2024-06-11 23:46:32] INFO [liquibase.command] Using deploymentId: 
>>> 8174792776 <(817)%20479-2776>
>>> [2024-06-11 23:46:32] INFO [liquibase.changelog] Reading from 
>>> lmsdb.DATABASECHANGELOG
>>> Running Changeset: 
>>> liquibase/db1/sqlfiles/V0__create_lms_integration_tables.sql::raw::includeAll
>>> [2024-06-11 23:46:32] INFO [liquibase.ui] Running Changeset: 
>>> liquibase/db1/sqlfiles/V0__create_lms_integration_tables.sql::raw::includeAll
>>> [2024-06-11 23:46:32] INFO [liquibase.changelog] Custom SQL executed
>>> [2024-06-11 23:46:32] INFO [liquibase.changelog] ChangeSet 
>>> liquibase/db1/sqlfiles/V0__create_lms_integration_tables.sql::raw::includeAll
>>>  
>>> ran successfully in 31ms
>>>
>>> UPDATE SUMMARY
>>> Run:                          1
>>> Previously run:               0
>>> Filtered out:                 0
>>> -------------------------------
>>> Total change sets:            1
>>>
>>> [2024-06-11 23:46:32] INFO [liquibase.util] UPDATE SUMMARY
>>> [2024-06-11 23:46:32] INFO [liquibase.util] Run:                         
>>>  1
>>> [2024-06-11 23:46:32] INFO [liquibase.util] Previously run:             
>>>   0
>>> [2024-06-11 23:46:32] INFO [liquibase.util] Filtered out:               
>>>   0
>>> [2024-06-11 23:46:32] INFO [liquibase.util] 
>>> -------------------------------
>>> [2024-06-11 23:46:32] INFO [liquibase.util] Total change sets:           
>>>  1
>>> [2024-06-11 23:46:32] INFO [liquibase.util] Update summary generated
>>> [2024-06-11 23:46:32] INFO [liquibase.command] Update command completed 
>>> successfully.
>>> Liquibase: Update has been successful. Rows affected: 1
>>> [2024-06-11 23:46:32] INFO [liquibase.ui] Liquibase: Update has been 
>>> successful. Rows affected: 1
>>> [2024-06-11 23:46:32] INFO [liquibase.lockservice] Successfully released 
>>> change log lock
>>> [2024-06-11 23:46:32] INFO [liquibase.command] Command execution complete
>>> Liquibase command 'update' was executed successfully.
>>> [2024-06-11 23:46:32] INFO [liquibase.ui] Liquibase command 'update' was 
>>> executed successfully.
>>>
>>> > Task :generateJooq FAILED
>>> Running jOOQ code generation with URL: jdbc:mysql://localhost:50255/lmsdb
>>> Username: test
>>> Password: test
>>> Driver: com.mysql.cj.jdbc.Driver
>>> [main] WARN org.jooq.meta.AbstractDatabase - SQL exception            : 
>>> Exception while executing meta query: Cannot execute query. No JDBC 
>>> Connection configured
>>>
>>> If you think this is a bug in jOOQ, please report it here: 
>>> https://jooq.org/bug
>>>
>>> Note you can mute some exceptions using the configuration/onError flag
>>>
>>> ```sql
>>> select information_schema.SCHEMATA.SCHEMA_NAME
>>> from information_schema.SCHEMATA```
>>>
>>> [main] ERROR org.jooq.meta.AbstractDatabase - Code generation error    : 
>>> An error was encountered during code generation. This can have various 
>>> reasons:
>>>
>>> - There's a bug in jOOQ. Please report it here: https://jooq.org/bug
>>> - Your database user doesn't have the necessary privileges to access a 
>>> metadata table
>>> - The database connection suffered a failure
>>>
>>> There are other reasons. If the error can be ignored, you can either:
>>>
>>> - Turn off the relevant feature in the code generator to avoid running 
>>> into the error
>>> - Avoid fetching the relevant meta data by excluding the object from 
>>> code generation
>>> - Use the <onError/> code generation configuration to specify the 
>>> severity of such errors (for all errors!)
>>>
>>> See 
>>> https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-onerror/
>>>
>>> [main] ERROR org.jooq.codegen.GenerationTool - Error in file: 
>>> /Users/dpatra/Downloads/HSLab/BEServices/PartnerServices/lms-registration-service/build/tmp/generateJooq/config.xml.
>>>  
>>> Error : Error generating code for catalog
>>> org.jooq.codegen.GeneratorException: Error generating code for catalog
>>>         at 
>>> org.jooq.codegen.JavaGenerator.generate0(JavaGenerator.java:542)
>>>         at 
>>> org.jooq.codegen.AbstractGenerator.generate(AbstractGenerator.java:191)
>>>         at 
>>> org.jooq.codegen.JavaGenerator.generate(JavaGenerator.java:225)
>>>         at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:944)
>>>         at org.jooq.codegen.GenerationTool.run(GenerationTool.java:244)
>>>         at 
>>> org.jooq.codegen.GenerationTool.generate(GenerationTool.java:239)
>>>         at org.jooq.codegen.GenerationTool.main(GenerationTool.java:211)
>>> Caused by: java.lang.RuntimeException: 
>>> org.jooq.exception.DetachedException: Cannot execute query. No JDBC 
>>> Connection configured
>>>         at 
>>> org.jooq.meta.AbstractDatabase.onError(AbstractDatabase.java:3886)
>>>         at 
>>> org.jooq.meta.AbstractDatabase.getSchemata(AbstractDatabase.java:759)
>>>         at 
>>> org.jooq.meta.AbstractDatabase.getSchemata(AbstractDatabase.java:779)
>>>         at 
>>> org.jooq.meta.CatalogDefinition.getSchemata(CatalogDefinition.java:65)
>>>         at 
>>> org.jooq.codegen.JavaGenerator.generateCatalogIfEmpty(JavaGenerator.java:574)
>>>         at 
>>> org.jooq.codegen.JavaGenerator.generate0(JavaGenerator.java:536)
>>>         ... 6 more
>>> Caused by: org.jooq.exception.DetachedException: Cannot execute query. 
>>> No JDBC Connection configured
>>>         at org.jooq_3.18.15.MYSQL.debug(Unknown Source)
>>>         at org.jooq.impl.AbstractQuery.connection(AbstractQuery.java:393)
>>>         at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:306)
>>>         at 
>>> org.jooq.impl.AbstractResultQuery.fetchLazy(AbstractResultQuery.java:301)
>>>         at 
>>> org.jooq.impl.AbstractResultQuery.fetchLazyNonAutoClosing(AbstractResultQuery.java:322)
>>>         at 
>>> org.jooq.impl.SelectImpl.fetchLazyNonAutoClosing(SelectImpl.java:2862)
>>>         at 
>>> org.jooq.impl.ResultQueryTrait.collect(ResultQueryTrait.java:360)
>>>         at 
>>> org.jooq.meta.mysql.MySQLDatabase.getSchemata0(MySQLDatabase.java:426)
>>>         at 
>>> org.jooq.meta.AbstractDatabase.lambda$getSchemata$2(AbstractDatabase.java:759)
>>>         at 
>>> org.jooq.meta.AbstractDatabase.onError(AbstractDatabase.java:3860)
>>>         ... 11 more
>>>
>>> FAILURE: Build failed with an exception.
>>>
>>> * What went wrong:
>>> Execution failed for task ':generateJooq'.
>>> > Process 'command 
>>> '/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home/bin/java''
>>>  
>>> finished with non-zero exit value 255
>>>
>>> * Try:
>>> > Run with --stacktrace option to get the stack trace.
>>> > Run with --info or --debug option to get more log output.
>>> > Run with --scan to get full insights.
>>> > Get more help at https://help.gradle.org.
>>>
>>> Deprecated Gradle features were used in this build, making it 
>>> incompatible with Gradle 9.0.
>>>
>>> You can use '--warning-mode all' to show the individual deprecation 
>>> warnings and determine if they come from your own scripts or plugins.
>>>
>>> For more on this, please refer to 
>>> https://docs.gradle.org/8.7/userguide/command_line_interface.html#sec:command_line_warnings
>>>  
>>> in the Gradle documentation.
>>>
>>> BUILD FAILED in 18s
>>> 6 actionable tasks: 6 executed
>>>
>>> Here is my three files.
>>>
>>> // mysql-tc.gradle
>>>
>>> import org.testcontainers.containers.MySQLContainer
>>>
>>> buildscript {
>>> repositories {
>>> mavenCentral()
>>> }
>>> dependencies {
>>> classpath "org.testcontainers:testcontainers:${testcontainersVersion}"
>>> classpath "org.testcontainers:mysql:${testcontainersVersion}"
>>> classpath "com.mysql:mysql-connector-j:8.4.0"
>>> }
>>> }
>>>
>>> tasks.register('startMySQLContainer') {
>>> println("----Stating MySql DB TC----")
>>> doLast {
>>> def mysqlContainer = new MySQLContainer("mysql:latest")
>>> .withDatabaseName("lmsdb")
>>> mysqlContainer.start()
>>>
>>> project.ext.dbUrl = mysqlContainer.getJdbcUrl()
>>> project.ext.dbUsername = mysqlContainer.getUsername()
>>> project.ext.dbPassword = mysqlContainer.getPassword()
>>> project.ext.dbDriver = mysqlContainer.getDriverClassName()
>>> println("----MySql Test container started successfully with URL : ${
>>> project.ext.dbUrl}")
>>> }
>>> }
>>>
>>> tasks.register('stopMySqlContainer') {
>>> doLast {
>>> if (mysqlContainer) {
>>> mysqlContainer.stop()
>>> }
>>> }
>>> }
>>>
>>> // liquibase.gradle
>>>
>>> configurations {
>>> liquibaseRuntime.extendsFrom runtimeClasspath
>>> }
>>>
>>> dependencies {
>>> liquibaseRuntime sourceSets.main.output
>>> implementation 'org.liquibase:liquibase-core:4.24.0'
>>> implementation 'info.picocli:picocli:4.7.6'
>>> }
>>>
>>> tasks.named('startMySQLContainer').configure {
>>> doLast {
>>> liquibase {
>>> activities {
>>> main {
>>> changelogFile 'liquibase/db1/tc_changelog.yml'
>>> url project.ext.has('dbUrl') ? project.ext.dbUrl : ''
>>> username project.ext.has('dbUsername') ? project.ext.dbUsername : ''
>>> password project.ext.has('dbPassword') ? project.ext.dbPassword : ''
>>> }
>>> }
>>> runList = 'main'
>>> }
>>> }
>>> }
>>>
>>> tasks.named('update') {
>>> dependsOn ':startMySQLContainer'
>>> }
>>>
>>> // jooq.gradle
>>>
>>> /**
>>> * This gradle file is used to generate JOOQ DAO, POJOs and fluent API 
>>> for writing SQL queries using
>>> * generated classes. The default configuration below should work in most 
>>> cases, but it can be
>>> * modified as needed based on the plugin documentation:
>>> *
>>> * https://github.com/etiennestuder/gradle-jooq-plugin
>>> */
>>>
>>> import nu.studer.gradle.jooq.JooqGenerate
>>>
>>> buildscript {
>>> repositories {
>>> gradlePluginPortal()
>>> }
>>> dependencies {
>>> classpath "nu.studer:gradle-jooq-plugin:${jooqPluginVersion}"
>>> }
>>> ext {
>>> // use jOOQ version defined in Spring Boot
>>> jooqVersion = dependencyManagement.importedProperties['jooq.version']
>>> }
>>> configurations.classpath {
>>> // Enforce the jOOQ configuration XML schema version
>>> resolutionStrategy.eachDependency {
>>> if (requested.group == 'org.jooq' && requested.name.startsWith('jooq')) 
>>> {
>>> useVersion jooqVersion
>>> }
>>> }
>>> }
>>> }
>>>
>>> apply plugin: nu.studer.gradle.jooq.JooqPlugin
>>>
>>> println("Configuring JOOQ dependencies and code generation plugin...")
>>>
>>> // JOOQ dependencies
>>> dependencies {
>>> implementation 'org.springframework.boot:spring-boot-starter-jooq'
>>> jooqGenerator 'com.mysql:mysql-connector-j'
>>> jooqGenerator 'org.slf4j:slf4j-simple'
>>>
>>> jooqGenerator 'com.fasterxml.jackson.core:jackson-databind'
>>> jooqGenerator "org.testcontainers:mysql"
>>> jooqGenerator 'software.aws.rds:aws-mysql-jdbc:1.+'
>>> implementation 'org.testcontainers:jdbc'
>>> }
>>>
>>> // Configure JOOQ
>>> jooq {
>>> version = jooqVersion
>>>
>>> configurations {
>>> main {
>>> generationTool {
>>> logging = org.jooq.meta.jaxb.Logging.WARN
>>> jdbc {
>>> driver = 'org.testcontainers.jdbc.ContainerDatabaseDriver'
>>> }
>>> generator {
>>> name = 'org.jooq.codegen.DefaultGenerator'
>>> database {
>>> name = 'org.jooq.meta.mysql.MySQLDatabase'
>>> inputSchema = 'lmsdb'
>>> }
>>> generate {
>>> records = true
>>> immutablePojos = true
>>> fluentSetters = true
>>> javaTimeTypes = false
>>> }
>>> target {
>>> packageName = "com.chegg.${mainPackageName}.db"
>>> }
>>> strategy.name = 'org.jooq.codegen.DefaultGeneratorStrategy'
>>> }
>>> }
>>> }
>>> }
>>> }
>>>
>>>
>>> jooq.configurations.main {
>>> generationTool {
>>> jdbc {
>>> url = project.ext.has('dbUrl') ? project.ext.dbUrl : ''
>>> user = project.ext.has('dbUsername') ? project.ext.dbUsername : ''
>>> password = project.ext.has('dbPassword') ? project.ext.dbPassword : ''
>>> driver = project.ext.has('dbDriver') ? project.ext.dbDriver : ''
>>> }
>>> }
>>> }
>>>
>>>
>>> // Configure the JVM used for the JOOQ code generation process
>>> tasks.withType(JooqGenerate).configureEach {
>>> javaExecSpec = { JavaExecSpec s ->
>>> s.systemProperties System.properties
>>> }
>>> }
>>>
>>> tasks.named('generateJooq') {
>>> dependsOn ':startMySQLContainer', ':update'
>>> doFirst {
>>> println "Running jOOQ code generation with URL: ${project.ext.dbUrl}"
>>> println "Username: ${project.ext.dbUsername}"
>>> println "Password: ${project.ext.dbPassword}"
>>> println "Driver: ${project.ext.dbDriver}"
>>> }
>>> }
>>>
>>> On Tuesday, June 11, 2024 at 12:04:45 AM UTC-7 lukas...@gmail.com wrote:
>>>
>>>> Thanks for your message. We'll have gradle examples eventually in our 
>>>> MCVE template:
>>>> https://github.com/jOOQ/jOOQ-mcve/issues/41
>>>>
>>>> They'll be using testcontainers too.
>>>>
>>>> Unfortunately, until then, I can't really comment about the "best way" 
>>>> to do it. (It will be very hard with gradle anyway, because there are so 
>>>> many opinions). We'll be recommending the official plugin, not a third 
>>>> party one...
>>>>
>>>> On Tue, Jun 11, 2024 at 7:28 AM Debapriya Patra <debapri...@gmail.com> 
>>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> Does anyone integrated Liquibase in a mysql testcontainer to apply DB 
>>>>> migrations and use Jooq to connect to the MySql test container DB to 
>>>>> generate java files?
>>>>>
>>>>> I wanted to do this inside a gradle Spring Boot  application. Can 
>>>>> someone help me on this ?
>>>>>
>>>>> Any example or reference might be helpful ?
>>>>>
>>>>> I am trying to go in the following sequence.
>>>>>
>>>>> - Spinup MySql test container
>>>>> - Apply DB migrations using Liquibase against MySql test container.
>>>>> - Generate Java files from the DB against MySql testcontainer DB.
>>>>>
>>>>> Also I wanted to have the code separated in three .gradle files.
>>>>> Here is what I have started with 
>>>>>
>>>>> *mysqltc.gradle*
>>>>> ------------------------
>>>>> ```
>>>>> // mysql-tc.gradle
>>>>>
>>>>> import org.testcontainers.containers.MySQLContainer
>>>>>
>>>>> buildscript {
>>>>> repositories {
>>>>> mavenCentral()
>>>>> }
>>>>> dependencies {
>>>>> classpath "org.testcontainers:testcontainers:${testcontainersVersion}"
>>>>> classpath "org.testcontainers:mysql:${testcontainersVersion}"
>>>>> classpath "com.mysql:mysql-connector-j:8.4.0"
>>>>> }
>>>>> }
>>>>>
>>>>> tasks.register('startMySQLContainer') {
>>>>> println("----Stating MySql DB TC----")
>>>>> doLast {
>>>>> def mysqlContainer = new MySQLContainer("mysql:latest")
>>>>> .withDatabaseName("lmsdb")
>>>>> .withUsername("test")
>>>>> .withPassword("test")
>>>>> mysqlContainer.start()
>>>>>
>>>>> project.ext.dbUrl = mysqlContainer.getJdbcUrl()
>>>>> project.ext.dbUsername = mysqlContainer.getUsername()
>>>>> project.ext.dbPassword = mysqlContainer.getPassword()
>>>>> project.ext.dbDriver = mysqlContainer.getDriverClassName()
>>>>>
>>>>> println "MySQL container started with URL: ${project.ext.dbUrl}"
>>>>> }
>>>>> }
>>>>>
>>>>> tasks.register('stopMySqlContainer') {
>>>>> doLast {
>>>>> if (mysqlContainer) {
>>>>> mysqlContainer.stop()
>>>>> }
>>>>> }
>>>>> }
>>>>> ```
>>>>>
>>>>> * liquibase.gradle*
>>>>> ```
>>>>> println("----Configuring Liquibase----")
>>>>> dependencies {
>>>>> implementation 'org.liquibase:liquibase-core:4.24.0'
>>>>> }
>>>>>
>>>>> liquibase {
>>>>> activities {
>>>>> main {
>>>>> changeLogFile 'src/main/resources/db/changelog/changelog-master.sql'
>>>>> url project.ext.has('d') ? project.ext.jdbcUrl : 
>>>>> 'jdbc:tc:mysql:8.0.36:///lmsdb?TC_TMPFS=/testtmpfs:rw'
>>>>> username project.ext.has('username') ? project.ext.username : 'test'
>>>>> password project.ext.has('password') ? project.ext.password : 'test'
>>>>> }
>>>>> }
>>>>> runList = 'main'
>>>>> }
>>>>>
>>>>> tasks.named('update') {
>>>>> dependsOn ':startMySQLContainer'
>>>>> }
>>>>> ```
>>>>>
>>>>> *jooq.gradle*
>>>>> -------------------
>>>>> ```/**
>>>>> * This gradle file is used to generate JOOQ DAO, POJOs and fluent API 
>>>>> for writing SQL queries using
>>>>> * generated classes. The default configuration below should work in 
>>>>> most cases, but it can be
>>>>> * modified as needed based on the plugin documentation:
>>>>> *
>>>>> * https://github.com/etiennestuder/gradle-jooq-plugin
>>>>> */
>>>>>
>>>>> import nu.studer.gradle.jooq.JooqGenerate
>>>>>
>>>>> buildscript {
>>>>> repositories {
>>>>> gradlePluginPortal()
>>>>> }
>>>>> dependencies {
>>>>> classpath "nu.studer:gradle-jooq-plugin:${jooqPluginVersion}"
>>>>> }
>>>>> ext {
>>>>> // use jOOQ version defined in Spring Boot
>>>>> jooqVersion = dependencyManagement.importedProperties['jooq.version']
>>>>> }
>>>>> configurations.classpath {
>>>>> // Enforce the jOOQ configuration XML schema version
>>>>> resolutionStrategy.eachDependency {
>>>>> if (requested.group == 'org.jooq' && requested.name.startsWith('jooq')) 
>>>>> {
>>>>> useVersion jooqVersion
>>>>> }
>>>>> }
>>>>> }
>>>>> }
>>>>>
>>>>> apply plugin: nu.studer.gradle.jooq.JooqPlugin
>>>>>
>>>>> println("Configuring JOOQ dependencies and code generation plugin...")
>>>>>
>>>>> // JOOQ dependencies
>>>>> dependencies {
>>>>> implementation 'org.springframework.boot:spring-boot-starter-jooq'
>>>>> jooqGenerator 'com.mysql:mysql-connector-j'
>>>>> jooqGenerator 'org.slf4j:slf4j-simple'
>>>>>
>>>>> jooqGenerator 'com.fasterxml.jackson.core:jackson-databind'
>>>>> jooqGenerator "org.testcontainers:mysql"
>>>>> jooqGenerator 'software.aws.rds:aws-mysql-jdbc:1.+'
>>>>> implementation 'org.testcontainers:jdbc'
>>>>> }
>>>>>
>>>>> // Configure JOOQ
>>>>> jooq {
>>>>> version = jooqVersion
>>>>>
>>>>> configurations {
>>>>> main {
>>>>> generationTool {
>>>>> logging = org.jooq.meta.jaxb.Logging.WARN
>>>>> jdbc {
>>>>> driver = 'org.testcontainers.jdbc.ContainerDatabaseDriver'
>>>>> }
>>>>> generator {
>>>>> name = 'org.jooq.codegen.DefaultGenerator'
>>>>> database {
>>>>> name = 'org.jooq.meta.mysql.MySQLDatabase'
>>>>> inputSchema = 'lmsdb'
>>>>> }
>>>>> generate {
>>>>> records = true
>>>>> immutablePojos = true
>>>>> fluentSetters = true
>>>>> javaTimeTypes = false
>>>>> }
>>>>> target {
>>>>> packageName = "com.chegg.${mainPackageName}.db"
>>>>> }
>>>>> strategy.name = 'org.jooq.codegen.DefaultGeneratorStrategy'
>>>>> }
>>>>> }
>>>>> }
>>>>> }
>>>>> }
>>>>>
>>>>> // Add database-specific JDBC driver dependencies for JOOQ code 
>>>>> generation and plugin configuration
>>>>> String databaseType = findProperty("databaseType") as String
>>>>>
>>>>> if (databaseType == "aurora-mysql") {
>>>>> ext.jooqSecrets = project.getSecretsById(project.getPropertyValue(
>>>>> "app.db.app-secret-id"))
>>>>>
>>>>> jooq.configurations.main {
>>>>> generationTool {
>>>>> jdbc {
>>>>> //url = "jdbc:mysql://" + 
>>>>> (project.getPropertyValue("spring.datasource.url") as 
>>>>> String).split("://", 
>>>>> 2)[1]
>>>>> //user = jooqSecrets.get("username")
>>>>> //password = jooqSecrets.get("password")
>>>>> url = project.ext.has('jdbcUrl') ? project.ext.jdbcUrl : 
>>>>> 'jdbc:tc:mysql:8.0.36:///lmsdb?TC_TMPFS=/testtmpfs:rw'
>>>>> }
>>>>> }
>>>>> }
>>>>> } else if (databaseType == "mysql") {
>>>>> jooq.configurations.main {
>>>>> generationTool {
>>>>> jdbc {
>>>>> url = project.getPropertyValue("spring.datasource.url")
>>>>> user = project.getPropertyValue("spring.datasource.username")
>>>>> password = project.getPropertyValue("spring.datasource.password")
>>>>> }
>>>>> }
>>>>> }
>>>>> }
>>>>>
>>>>> // Configure the JVM used for the JOOQ code generation process
>>>>> tasks.withType(JooqGenerate).configureEach {
>>>>> javaExecSpec = { JavaExecSpec s ->
>>>>> s.systemProperties System.properties
>>>>> }
>>>>> }
>>>>>
>>>>> tasks.named('generateJooq') {
>>>>> dependsOn ':startMySQLContainer', ':update'
>>>>> }```
>>>>>
>>>>> In my build.gradle I am applying from those three .gradle files.
>>>>>
>>>>> I am stuck with an error.
>>>>>
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "jOOQ User Group" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to jooq-user+...@googlegroups.com.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/jooq-user/61012e09-94c7-4287-b1fd-7254fee3178en%40googlegroups.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/jooq-user/61012e09-94c7-4287-b1fd-7254fee3178en%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "jOOQ User Group" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to jooq-user+...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/jooq-user/35cfebbd-cf64-43f0-af31-c9e5af5239d1n%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/jooq-user/35cfebbd-cf64-43f0-af31-c9e5af5239d1n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "jOOQ User Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to jooq-user+...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jooq-user/CAB4ELO4cfBGO-aWfqZ_Gm3DGqJEJ4-7uL6fU%3D8QR6quK3%2BPTeA%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/jooq-user/CAB4ELO4cfBGO-aWfqZ_Gm3DGqJEJ4-7uL6fU%3D8QR6quK3%2BPTeA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jooq-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jooq-user/0de7d4ed-71e5-451b-ab2c-0ab6b6f258b6n%40googlegroups.com.

Reply via email to