Problem when defining custom GeneratorStrategy (gradle)

266 views
Skip to first unread message

christi...@gmail.com

unread,
Jun 17, 2016, 2:43:46 AM6/17/16
to jOOQ User Group
Hi Lukas,

I'm running into a problem when I try to define my own GeneratorStrategy. The classloader doesn't find my strategy class and I can't figure out how this can be solved.
I use jOOQ 3.7.3 to generate the code.
For creating the classes I've a gradle script which looks like this:


...

def dbProps = new Properties()
dbProps
.load(new FileInputStream(System.getProperty("user.home") + "/local.properties"))

ext
{

 database
= [
 host
: dbProps.get("dbHost"),
 port
: dbProps.get("dbPort"),
 schema
: dbProps.get("dbSchema"),
 user
: dbProps.get("dbUser"),
 password
: dbProps.get("dbPwd")
 
]

 jooqGen
= [ metaSrcDir: "$buildDir/generated" ]

 jdbcUrl
= "jdbc:mysql://${database.host}:${database.port}/${database.schema}"

}

defaultTasks
'jooqMetaGenerate'

configurations
{
 compile
.extendsFrom generatedCompile
}

sourceSets
{
    generated

    main
{
        compileClasspath
+= generated.output
        output
.classesDir = "$buildDir/classes"
        output
.resourcesDir = "$buildDir/resources"

        java
{
            srcDirs
+= [jooqGen.metaSrcDir]
       
}

        resources
   
}

}

dependencies
{
 generatedCompile 'org.jooq:jooq:3.7.3', 'org.jooq:jooq-meta:3.7.3', 'org.jooq:jooq-codegen:3.7.3'
 
...
}

...

task
("jooqMetaGenerate") << {
 
Configuration configuration = new Configuration()
   
.withJdbc(new Jdbc()
       
.withUrl(jdbcUrl)
       
.withUser(database.user)
       
.withPassword(database.password))
   
.withGenerator(new Generator()
       
.withStrategy(new Strategy()
           
.withName('my.own.package.util.MyGeneratorStrategy'))
       
.withGenerate(new Generate()
           
.withValidationAnnotations(true)
           
.withPojos(true).withPojosEqualsAndHashCode(true).withPojosToString(true).withImmutablePojos(true))
       
.withDatabase(new Database()
           
.withSchemata(new Schema()
           
.withInputSchema(database.schema)
           
.withOutputSchema(database.schema))
       
.withName("org.jooq.util.mysql.MySQLDatabase"))
   
.withTarget(new Target()
       
.withPackageName("my.own.package")
       
.withDirectory(jooqGen.metaSrcDir)));

 
GenerationTool.generate(configuration)
}


flywayMigrate
.dependsOn clean
compileGeneratedJava
.dependsOn jooqMetaGenerate
compileJava
.dependsOn compileGeneratedJava


The "jooqMetaGenerate" task gives me the class not found exception:
Caused by: java.lang.ClassNotFoundException: my.own.package.util.MyGeneratorStrategy 
  at org.jooq.util.GenerationTool.loadClass(GenerationTool.java:500)
  at org.jooq.util.GenerationTool.run(GenerationTool.java:236) 
  at org.jooq.util.GenerationTool.generate(GenerationTool.java:180) 

Any idea how I can make the classloader look for the strategy class?

Thanks in advance...

Cheers,
Christian

Lukas Eder

unread,
Jun 17, 2016, 3:40:49 AM6/17/16
to jooq...@googlegroups.com
Hi Christian,

I'm not too acquainted with how Gradle works, so perhaps this is not the best answer, but in Maven, you would have to create a separate project/module only for that strategy class, in order to create a dependency graph like so:

1. Code generation module... depends on
2. Strategy module... depends on
3. jOOQ libraries

I would imagine that it is the same with Gradle.

I hope this helps,
Lukas

--
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.
For more options, visit https://groups.google.com/d/optout.

Christian Meyer

unread,
Jun 17, 2016, 5:35:48 AM6/17/16
to jOOQ User Group
Hi Lukas,

thanks for your reply. I thought that this would be the only solution. Is there any maven example where I can look at? So far I haven't found anything.

ciao
Christian

Christian Meyer

unread,
Jun 17, 2016, 8:37:34 AM6/17/16
to jOOQ User Group
Hi again,

I figured it out myself and it fortunately works now :-)

Since this could be helpful for everyone else, what do you think about having an example in jooq?

ciao
Christian

Lukas Eder

unread,
Jun 25, 2016, 8:48:35 AM6/25/16
to jooq...@googlegroups.com
Hi Christian,

2016-06-17 14:37 GMT+02:00 Christian Meyer <christi...@gmail.com>:
Hi again,

I figured it out myself and it fortunately works now :-)

Excellent!
 
Since this could be helpful for everyone else, what do you think about having an example in jooq?

Right now, I'd like to avoid adding too many Gradle examples to the manual as it would just be a lot of manual maintenance work. What would be excellent is:

- A blog post
- A Stack Overflow question / answer. This is a very nice tool to document things, people often do it, they answer their own questions to share knowledge

Both options will help people find things from google much more easily than browsing discussions here on the user group.

Hope this helps,
Lukas

kathlee...@signavio.com

unread,
May 4, 2017, 6:17:24 AM5/4/17
to jOOQ User Group
Hi Christian,

I am having the same problem, did you post your solution anywhere?

Kathleen
Reply all
Reply to author
Forward
0 new messages