jooq-codegen-maven plugin for different db at the same time - java

I use jOOQ and MySQL DB in my application. For integration tests I use H2 database and there is a problem. Is there some way to run jooq-codegen-maven plugin twice? I found some maven example for this case. However, in two different cases, I must use two different dependencies. Can I somehow to include dependency in execution?

You can have multiple <execution> elements in any Maven plugin configuration, e.g.
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.9.1</version>
<executions>
<execution>
<id>first-generation</id>
<phase>generate-sources</phase>
<goals><goal>generate</goal></goals>
<configuration>
<!-- jOOQ configuration here -->
</configuration>
</execution>
<execution>
<id>second-generation</id>
<phase>generate-sources</phase>
<goals><goal>generate</goal></goals>
<configuration>
<!-- jOOQ configuration here -->
</configuration>
</execution>
</executions>
</plugin>

Related

flyway-maven-plugin: how to execute multiple database configurations together?

I am integrating Flyway in to an existing legacy project, which consists of multiple databases for the same application. The project uses Maven and I want to use the maven-flyway-plugin to integrate with Flyway.
My working configuration so far looks like this:
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<executions>
<execution>
<id>db1</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
...
</configuration>
</execution>
<execution>
<id>db2</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
...
</configuration>
</execution>
<execution>
<id>db2</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin>
With this I can migrate each database separately like this:
mvn flyway:migrate#db1 flyway:migrate#db2 flyway:migrate#db3
Unfortunately this is not very user friendly. I want to be able to simply execute mvn flyway:migrate and execute all three migration configurations.
How can I achieve that?
maven works this way. You can either extends flyway plugin with your needs or you can migrate to gradle which can gather multiple 'job'
Eric

Combining Querydsl-jpa and querydsl-sql and code generation

Here is the thing:
I have been using querydsl-jpa in my projects and code generation has never been a problem. I use this plugin in maven:
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/generated-sources</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
Now, I need to also use querydsl-sql and apparently, I can't use the Q-generated classes created by com.querydsl.apt.jpa.JPAAnnotationProcessor. Here is the plugin in maven:
<plugin>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>4.2.1</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbcDriver>com.mysql.cj.jdbc.Driver</jdbcDriver>
<jdbcUrl>jdbc:mysql://localhost:3306/mydatabase</jdbcUrl>
<jdbcUser>root</jdbcUser>
<jdbcPassword></jdbcPassword>
<packageName>com.myproject.domain</packageName>
<targetFolder>${project.basedir}/target/generated-sources/java</targetFolder>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
</dependencies>
</plugin>
THE CHALLENGE
The second plugin above generates Q-classes for all schemas in my DBMS (MySql) whereas I have specified the schema to generate Q-classes from.
How do I specify the username, password and jdbcUrl from a file since I don't want to store sensitive information in the git repository.
Here are my solutions:
For challenge one, I haven't found a solution per se but some sort of workaround. I created a user in my DBMS (MySql) that has privileges on the single schema that I am interested in. That way, the user won't be able to generate Q-classes for other schemas. So problem one "solved".
Though I still believe that in the plugin one should be able to specify the schema to be generated. Interestingly enough <schemaPattern></schemaPattern> as suggested by #Rober Bain which is also in the querydsl-sql documentation does not work.
For challenge two, first you need to create a properties files say dev.properties with the needed content
jdbc-url=jdbc:mysql://localhost:3306/myschema?nullNamePatternMatchesAll=true
jdbc-user=my_user
jdbc-password=my_password
Then, include the following properties-maven-plugin
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>dev.properties</file> // Reference to properties file
</files>
</configuration>
</execution>
</executions>
</plugin>
... and in your query-dsl plugin ...
<plugin>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>4.2.1</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
<configuration>
<jdbcDriver>com.mysql.jdbc.Driver</jdbcDriver>
<jdbcUrl>${jdbc-url}</jdbcUrl>
<jdbcUser>${jdbc-user}</jdbcUser>
<jdbcPassword>${jdbc-password}</jdbcPassword>
<packageName>com.myproject.domain</packageName>
<targetFolder>${project.basedir}/target/generated-sources/java</targetFolder>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
</dependencies>
</plugin>
Check out this link for more info Read pom.xml configurations from properties file
Since the above link is down, use Wayback Online to see the original web page.
or
Here is a snapshot of the content
and a continuation
Use schemaPattern within the configuration element: "a schema name pattern in LIKE pattern form; must match the schema name as it is stored in the database, multiple can be separated by comma (default: null)" from the querydsl docs.
While the doesn't do exactly what you're asking for, I believe it's the standard way of solving this problem. Use encrypted data in a Maven pom.

sql-maven-plugin: clean multiple databases?

I would like to clean and fill two different databases for integration testing with a Maven project. I use the sql-maven-plugin, but I wasn't able to make it handle different databases (I can have only one plugin declaration for the sql-maven-plugin, and the configuration is shared between its executions).
How do you guys solve that? Is there any workaround to solve this issue?
Thanks in advance!
You can simply define all of the configuration within each individual execution section and configure as required. Instead of having a shared configuration.
So here is an example to connect to two different HSQLDB databases:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.9</version>
</dependency>
<!-- you could add dependencies to other database drivers here -->
</dependencies>
<executions>
<!-- execution against database 1 -->
<execution>
<id>database1</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<!-- specific configuration for execution against database1 -->
<configuration>
<driver>org.hsqldb.jdbcDriver</driver>
<url>jdbc:hsqldb:hsql://localhost:9999/database1</url>
<username>sa</username>
<password></password>
<sqlCommand>select count(TYPE_NAME) from INFORMATION_SCHEMA.SYSTEM_TABLES</sqlCommand>
</configuration>
</execution>
<!-- execution against database 2 -->
<execution>
<id>database2</id>
<phase>process-test-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<!-- specific configuration for execution against database2 -->
<configuration>
<driver>org.hsqldb.jdbcDriver</driver>
<url>jdbc:hsqldb:hsql://localhost:8888/database2</url>
<username>sa</username>
<password></password>
<sqlCommand>select count(TYPE_NAME) from INFORMATION_SCHEMA.SYSTEM_TABLES</sqlCommand>
</configuration>
</execution>
</executions>
</plugin>

Customize package for QueryDSL output

I am creating QueryDSL objects for MongoDB using Maven, here's the build xml,
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>src/main/java</outputDirectory>
<!-- This processor uses the Spring MongoDB annotations for processing -->
<processor>org.springframework.data.mongodb.repository.support.MongoAnnotationProcessor</processor>
</configuration>
</plugin>
</plugins>
</build>
But its generating the query class QDomain for Domain in the same package as Domain.
Can the plugin be customized to put Query classes in a separate package?
You can use the querydsl.packageSuffix APT option to add a suffix to your generated package. Just add the following block inside configuration
<options>
<querydsl.packageSuffix>.query</querydsl.packageSuffix>
</options>

GWT, Maven and AspectJ: RequestFactory validation for AOPed code?

To use GWT 2.4.0 RequestFactory, you have to run request factory validation tool. Otherwise, it just won't work. [Google says][1], that it's enough just to add 2 plugins to pom.xml:
<!-- requestfactory-apt runs an annotation processor (APT) to
instrument its service interfaces so that
RequestFactoryServer can decode client requests. Normally
you would just have a dependency on requestfactory-apt
with <scope>provided</scope>, but that won't work in
eclipse due to m2e bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=335036 -->
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.0.5</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.google.web.bindery</groupId>
<artifactId>requestfactory-apt</artifactId>
<version>${gwtVersion}</version>
</dependency>
</dependencies>
</plugin>
<!-- Google Plugin for Eclipse (GPE) won't see the source
generated above by requestfactory-apt unless it is exposed
as an additional source dir-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/apt</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
The problem is, I have quite a complicated server-side code that uses AOP, so when validation tool is ran against that code, it fails because "there's no method xxx()", "class xxx doesn't implement interface yyy", etc.
So, my question is, is it possible to fix this issue on pom.xml level, rather then moving all AOP code into separate project that will be compiled separately?
Solved by moving all AOPed code to another project.

Categories