'Jooq code generation from multiple databases
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.
Solution 1:[1]
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())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HSLM |
