How to use the jooq-codegen Maven plugin with a custom strategy?

1,152 views
Skip to first unread message

Lukas Eder

unread,
Apr 25, 2012, 3:13:30 PM4/25/12
to jooq...@googlegroups.com
I've recently had a good question here about how to use the
jooq-codegen Maven plugin with a custom generator strategy:
https://sourceforge.net/apps/trac/jooq/ticket/1355

I raised the issue on Stack Overflow:
http://stackoverflow.com/questions/10322155/how-to-use-a-custom-strategy-with-the-jooq-code-generator-and-maven

Any ideas by the "Maven pros" on this list welcome! (feel free to
answer directly on Stack Overflow)

Cheers
Lukas

ericjs

unread,
Apr 26, 2012, 1:27:35 AM4/26/12
to jOOQ User Group
I'm definitely no maven expert, but I wonder if this is something of
circular dependency problem. If the custom strategy were in a
different project then it could be a dependency of the plugin, but if
it is in the same project...well I'm not sure how that works. At the
very least it seems to me that this would mean that the phase in which
the jooq codegen occurred would have to be a phase AFTER the compile
of the project code; and I assume that project code also would
dependitself uses the jooq generated classes which requires the
opposite.

On Apr 25, 3:13 pm, Lukas Eder <lukas.e...@gmail.com> wrote:
> I've recently had a good question here about how to use the
> jooq-codegen Maven plugin with a custom generator strategy:https://sourceforge.net/apps/trac/jooq/ticket/1355
>
> I raised the issue on Stack Overflow:http://stackoverflow.com/questions/10322155/how-to-use-a-custom-strat...

Lukas Eder

unread,
Apr 26, 2012, 2:35:52 AM4/26/12
to jooq...@googlegroups.com
Hello Eric,

Yes, that about describes the problem. So I'm just curious how to best
solve this. In principle, the strategy shouldn't be in src/main/java,
but in some other folder that can be compiled before generating the
sources.

If adding a new project can be avoided, all the better

Cheers
Lukas

2012/4/26 ericjs <ericjs...@gmail.com>:

Bondarenko Denis

unread,
Apr 26, 2012, 2:44:12 AM4/26/12
to jooq...@googlegroups.com
Hi, all

Imo:

If project is single-module type, than com.examle.MyStrategy should be
moved in separated project.
This separated project should produce, for example, this artefact:
<groupId>com.example</groupId>
<artifactId>jooq-strategy</artifactId>
<version>1.0.0.1</version>
And pom in original project should looks like this:
.....
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>2.2.2</version>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>jooq-strategy</artifactId>
<version>1.0.0.1</version>
</dependencies>
</dependency>
.....
If project is multi-module, than approach is slightly different.
com.examle.MyStrategy should be moved in separated module.
Module(where it will be used) should declare dependency on that.
And pom of original module should look like this:
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>2.2.2</version>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>jooq-strategy</artifactId>
<version>${project.version}</version>
</dependencies>
</dependency>

Btw, since it my first letter to this list, I want to express my
gratitude to Lukas for his amazing work on JOOQ.
Thank You, Lukas!

Best regards,
Denis

Sergey Epik

unread,
Apr 26, 2012, 4:58:54 AM4/26/12
to jooq...@googlegroups.com


On Thu, Apr 26, 2012 at 9:44 AM, Bondarenko Denis <danko...@gmail.com> wrote:
If project is multi-module, than approach is slightly different.
 com.examle.MyStrategy should be moved in separated module.
Module(where it will be used) should declare dependency on that.
And pom of original module should look like this:
<plugin>
 <groupId>org.jooq</groupId>
 <artifactId>jooq-codegen-maven</artifactId>
 <version>2.2.2</version>
 <dependencies>
    <dependency>
       <groupId>com.example</groupId>
       <artifactId>jooq-strategy</artifactId>
       <version>${project.version}</version>
    </dependencies>
  </dependency>


BTW: if com.examle.MyStrategy is moved into the separate module you have set preparationGoals for maven-release-plugin:

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.0</version>
                    <configuration>
                        <preparationGoals>clean install</preparationGoals>
                    </configuration>
                </plugin>

mx.m...@gmail.com

unread,
Apr 26, 2012, 9:17:21 AM4/26/12
to jooq...@googlegroups.com
Separate module is not a convenient way.
For my purpose, i want to change only the name of the Factory to application name.
I don't want to create a separate module for any new project for only this feature.
Lukas, what about rules tags like http://sourceforge.net/apps/trac/jooq/ticket/1171 ?

Message has been deleted
Message has been deleted

Lukas Eder

unread,
Apr 27, 2012, 4:50:14 AM4/27/12
to jooq...@googlegroups.com
Thanks everyone, for sharing their thoughts!

> Separate module is not a convenient way.
> [...]
> I don't want to create a separate module for any new project for only this
> feature.

I understand. Yet, creating a dedicated module seems to me the path of
least resistance.
You could, of course, build jooq-codegen yourself and add your own
strategy as a part of jooq-codegen directly in there. Then you
wouldn't have any issues with these dependencies.

> For my purpose, i want to change only the name of the Factory to application
> name.

Then again, you can extend the generated [Schema]Factory and use that instead.

> Lukas, what about rules tags
> like http://sourceforge.net/apps/trac/jooq/ticket/1171 ?

As the custom generator strategy turns out to be the most powerful
solution I could provide to users, #1171 is now at a lower prio. I
wonder whether supporting scripting languages, such as velocity,
wouldn't be much better than extending the strategy and Java-based
source code generation so much. Patches / implementation drafts for
#1171 are welcome, of course!

Cheers
Lukas
Reply all
Reply to author
Forward
0 new messages