0

How can I configure my maven to generate code from different databases? I have this configuration:

<plugin>
    <groupId>org.jooq</groupId>
    <artifactId>jooq-codegen-maven</artifactId>
    <version>3.16.1</version>
    <dependencies>
        <dependency>
            ...postgres dependency...
        </dependency>
    </dependencies>
    <executions>
        <execution>
            ...id-name...
            ...phase...
            ...goals...
            <configuration>
                <jdbc> 
                    <driver>org.postgresql.Driver</driver>
                    <url>'url'</url>
                    <user>'user'</user>
                    <password>'pswd'</password>
                </jdbc>
                <generator>
                    <database>
                       ...includes...
                       ...excludes...
                       ...inputSchema...
                    </database>
                    <generate>
                        <records>true</records>
                    </generate>
                    <target>
                        <packageName>com.example.testtask</packageName>
                        <directory>target/generated-sources/jooq</directory>
                    </target>
                </generator>
            </configuration>
        </execution>
        <execution>
            ...id-second-name...
             ...phase...
            ...goals...
            <configuration>
                <jdbc>  
                    <driver>org.postgresql.Driver</driver>
                    <url>'second-url'</url>
                    <user>'user'</user>
                    <password>'pswd'</password>
                </jdbc>
                <generator>
                    <database>
                       ...includes...
                       ...excludes...
                       ...inputSchema...
                    </database>
                    <generate>
                        ...
                    </generate>
                    <target>
                       ...
                    </target>
                </generator>
            </configuration>
        </execution>
    </executions>
</plugin> 

How to configure it correctly?
It works with one execution, but when I added the second one, the build failed.

Renis1235
  • 4,116
  • 3
  • 15
  • 27
alf3ratz
  • 21
  • 5

1 Answers1

0

When I have multiple databases I usually configure Jooq programmatically.

This is my kotlin code:

val DB1JooqCodeGenConfig =  JooqConfiguration()
            .withJdbc(
                Jdbc().apply {
                    username = env.getProperty("hikari.username")
                    password = env.getProperty("hikari.password")
                    url = env.getProperty("hikari.url")
                }
            )

            .withGenerator(
                Generator()
                    .withDatabase(
                        Database().apply {
                            withName("org.jooq.meta.mysql.MySQLDatabase")
                            withIncludes(".*")
                            withInputSchema("test")
                        }
                    )

                    .withTarget(org.jooq.meta.jaxb.Target().apply {
                        withPackageName("org.jooq.spring.generated")
                        withDirectory("app/build/classes/gen/")
                    })
            )

// ... plus the other DB
GenerationTool().run(DB1JooqCodeGenConfig())
GenerationTool().run(DB2JooqCodeGenConfig())
HSLM
  • 1,692
  • 10
  • 25