# Custom Generator Class not found by jOOQ codegen plugin

**URL:** <https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186>\
**Category:** Help/Discuss\
**Tags:** plugins\
**Created:** [June 23, 2019, 4:23pm UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186 "2019-06-23T16:23:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![elkebasel](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@elkebasel](https://discuss.gradle.org/u/elkebasel)\
**Post date:** [June 23, 2019, 4:23pm UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/1 "2019-06-23T16:23:41Z")

</div>

I have extended the JavaGenerator of jOOQs codegen classes and would like the gradle plugin use this Generator, used in IntelliJ. Of course, this class is in a package outside the jooq dependency.  
In spite of the fact that the compiled class is on the classpath I get a class not found exception.  
In the forum I found the recommendation to use the syntax name= MyCustomClass.class.canonicalName, which doesnt work.  
Does somebody have experience with that issue?  
Thank you very much in advance, best greetings, Elke

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [June 24, 2019, 9:38am UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/2 "2019-06-24T09:38:05Z")

</div>

Please note that the all of Gradle project classloaders are instantiated before a single class is compiled. So if you want to execute one of your compiled classes during the build, you’ll need to use another classloader. Eg:

```gradle
configurations {
   jooq
} 
dependencies {
   jooq project(':my-jooq-javagenerator') 
} 
task jooq {
   dependsOn ':my-jooq-javagenerator:classes' 
   doLast {
      List<URL> urls = configurations.jooq.collect { it.toURI().toURL() } 
      def cl = new UrlClassLoader(urls as URL[]) 
      Class myClass = cl.loadClass('foo.bar.MyJavaGenerator')
      def myGenerator = myClass.newInstance(...)
      myGenerator.doStuff(...)
   } 
} 

```

---

<div class="post-metadata">

**Author:** ![elkebasel](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@elkebasel](https://discuss.gradle.org/u/elkebasel)\
**Post date:** [June 24, 2019, 11:35am UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/3 "2019-06-24T11:35:22Z")

</div>

Thank you very much, dear Lance.

Two questions:

1. 

In my build.gradle UrlClassLoader can not be resolved (gradle 4.10.3 and Java 11.0.3 in IntelliJ) at the same time the .newInstance() Method is marked as deprecated.How to fix this?

I tried newer Versions of gradle but they do not work with Java11 and Intellij (invalid Type Code 85, according to this [https://intellij-support.jetbrains.com/hc/en-us/community/posts/360002683740-Gradle-failure-Java-11-with-Gradle-5-and-Cause-invalid-type-code-CD](https://intellij-support.jetbrains.com/hc/en-us/community/posts/360002683740-Gradle-failure-Java-11-with-Gradle-5-and-Cause-invalid-type-code-CD)).

1. Once the preload of the class is succeeded, how can I integrate it in my code?

Thank you very much in advance.

Best Elke

```gradle
jooq {

    version = '3.11.11'

    edition = 'OSS'

    sample(sourceSets.main) {

        jdbc {

            driver='org.postgresql.Driver'

            url='jdbc:postgresql://myServer/myDataBase'

            user='user'

            password='secret'

        }

        generator {

          

//original

            //name = 'org.jooq.codegen.JavaGenerator'

            // custom

             name = 'foo.bar.MyJavaGenerator'

            strategy {

               // name = 'nu.studer.sample.SampleGeneratorStrategy' // use the custom generator strategy

            }

            database {

                name = 'org.jooq.meta.postgres.PostgresDatabase'

                inputSchema = 'public'

            }

            target {

                packageName='dbgenerated'

                directory='src/main/java'

            }

        }

    }

}

``
Gesendet von [Mailspring](https://getmailspring.com/), der besten kostenlosen E-Mail-App für die Arbeit
```

---

<div class="post-metadata">

**Author:** ![elkebasel](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@elkebasel](https://discuss.gradle.org/u/elkebasel)\
**Post date:** [June 24, 2019, 11:47am UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/4 "2019-06-24T11:47:56Z")

</div>

Dear Lance

I solved the first question:

it was a Typo (URL instead of Url, and so I found also the new Code for the deprecated Method). Code below.

But Intellij tells my that this task cannot be applied to nu.studer.jooq.extension.

What can I do?

Thank you in advance, best greetings, Elke

```gradle
configurations {

    jooq

}

dependencies {

    jooq project(':my-jooq-javagenerator')

}

task jooq {

    dependsOn ':my-jooq-javagenerator:classes'

    doLast {

        List<URL> urls = configurations.jooq.collect { it.toURI().toURL() }

        def cl = new URLClassLoader(urls as URL[])

       

        Class myClass = cl.loadClass('foo.bar.MyJavaGenerator')

        def myGenerator = myClass.getDeclaredConstructor().newInstance()

       

    }

}

``

Gesendet von [Mailspring](https://getmailspring.com/), der besten kostenlosen E-Mail-App für die Arbeit
```

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [June 24, 2019, 11:56am UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/5 "2019-06-24T11:56:42Z")

</div>

Ah, sorry… I’ve led you on a bit of a wild goose chase there. If you want the jooq plugin to have your generator on its classpath you are best to put the java source in `buildSrc/src/main/java`.

You’ll need to add jooq to the compile time dependencies in `buildSrc/build.gradle`

---

<div class="post-metadata">

**Author:** ![elkebasel](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@elkebasel](https://discuss.gradle.org/u/elkebasel)\
**Post date:** [June 24, 2019, 2:21pm UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/6 "2019-06-24T14:21:21Z")

</div>

Dear Lance

To be sure: buildSrc means my project folder?

Jooq is of course in my dependencies, the Codegenerator works fine with the standard JavaGenerator.

```gradle
compile 'org.jooq:jooq'

compile 'org.jooq:jooq:3.11.11'

compile'org.jooq:jooq-scala_2.12:3.11.11'

compile 'org.jooq:jooq-meta-extensions:3.11.11'

compile 'org.jooq:jooq-meta:3.11.11'

compile 'org.jooq:jooq-codegen:3.11.11'

runtime 'org.postgresql:postgresql:42.2.5'

testCompile 'junit:junit:4.11'

jooqRuntime 'org.postgresql:postgresql:42.2.5'

``

I want to adopt my Records to JavaFX thats why I want to have an own generator.

My MyJavaGenerator.java is in src/main/java/foo/bar, consequently the compiled class in buildScr/build/classes/java/main/foo/bar. (this order in Intellij)

I try to access with

```

generator {

```
name = 'foo.bar.JavaFXGenerator'

```

```gradle
//name = 'org.jooq.codegen.JavaGenerator'

```

}

``  
What is wrong?

Perhaps I have to add something here?

```gradle
dependencies {

    classpath 'org.jooq:jooq-codegen:3.11.11'

    classpath 'com.h2database:h2:1.4.177'

    classpath 'org.postgresql:postgresql:42.2.5'

}

``
Best and thank you in advance, Elke

Gesendet von [Mailspring](https://getmailspring.com/), der besten kostenlosen E-Mail-App für die Arbeit
```

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [June 24, 2019, 2:36pm UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/7 "2019-06-24T14:36:15Z")

</div>

> To be sure: buildSrc means my project folder?

Incorrect, `buildSrc` is a special project which is implicit to every gradle build. It’s where you put custom build utilities that end up on the buildscript classpath.

See [Organizing Gradle Projects](https://docs.gradle.org/current/userguide/organizing_gradle_projects.html#sec:build_sources)

---

<div class="post-metadata">

**Author:** ![elkebasel](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@elkebasel](https://discuss.gradle.org/u/elkebasel)\
**Post date:** [June 24, 2019, 2:58pm UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/8 "2019-06-24T14:58:56Z")

</div>

Ok, thank you once more… This is new to me (I developed my project from a sample project without buildSrc), I will try and answer you.

Best, Elke

Gesendet von [Mailspring](https://getmailspring.com/), der besten kostenlosen E-Mail-App für die Arbeit

---

<div class="post-metadata">

**Author:** ![elkebasel](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@elkebasel](https://discuss.gradle.org/u/elkebasel)\
**Post date:** [June 25, 2019, 12:41pm UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/9 "2019-06-25T12:41:36Z")

</div>

Dear Lance

I included a buildSrc-folder in my project.

![Pasted File.png](https://global.discourse-cdn.com/gradle/original/2X/2/2ee5d952c82d4275da185660936fbbb475a5640d.png)

My buildSrc/build.gradle looks like:

```gradle

repositories {

    mavenCentral()

}

dependencies {

    compile 'org.jooq:jooq'

    compile 'org.jooq:jooq:3.11.11'

    compile'org.jooq:jooq-scala_2.12:3.11.11'

    compile 'org.jooq:jooq-meta-extensions:3.11.11'

    compile 'org.jooq:jooq-meta:3.11.11'

    compile 'org.jooq:jooq-codegen:3.11.11'

    runtime 'org.postgresql:postgresql:42.2.5'

    testCompile 'junit:junit:4.11'

    compile 'com.github.javaparser:javaparser-core:3.14.5'

}

``
The error I get is always the same:

14:34:03: Executing task 'build'...

> Task :buildSrc:compileJava UP-TO-DATE

> Task :buildSrc:compileGroovy NO-SOURCE

> Task :buildSrc:processResources NO-SOURCE

> Task :buildSrc:classes UP-TO-DATE

> Task :buildSrc:jar UP-TO-DATE

> Task :buildSrc:sourcesJar UP-TO-DATE

> Task :buildSrc:assemble UP-TO-DATE

> Task :buildSrc:compileTestJava NO-SOURCE

> Task :buildSrc:compileTestGroovy NO-SOURCE

> Task :buildSrc:processTestResources NO-SOURCE

> Task :buildSrc:testClasses UP-TO-DATE

> Task :buildSrc:test NO-SOURCE

> Task :buildSrc:check UP-TO-DATE

> Task :buildSrc:build UP-TO-DATE

> Task :wrapper

BUILD SUCCESSFUL in 0s

1 actionable task: 1 executed

> Task :buildSrc:compileJava UP-TO-DATE

> Task :buildSrc:compileGroovy NO-SOURCE

> Task :buildSrc:processResources NO-SOURCE

> Task :buildSrc:classes UP-TO-DATE

> Task :buildSrc:jar UP-TO-DATE

> Task :buildSrc:sourcesJar UP-TO-DATE

> Task :buildSrc:assemble UP-TO-DATE

> Task :buildSrc:compileTestJava NO-SOURCE

> Task :buildSrc:compileTestGroovy NO-SOURCE

> Task :buildSrc:processTestResources NO-SOURCE

> Task :buildSrc:testClasses UP-TO-DATE

> Task :buildSrc:test NO-SOURCE

> Task :buildSrc:check UP-TO-DATE

> Task :buildSrc:build UP-TO-DATE

> Task :generateSampleJooqSchemaSource FAILED

Juni 25, 2019 2:34:04 NACHM. org.jooq.tools.JooqLogger info

INFORMATION: Initialising properties : /home/elkemint/switchdrive/HLS/jpro/studentischeprojekte/build/tmp/generateSampleJooqSchemaSource/config.xml

WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/home/elkemint/.gradle/caches/modules-2/files-2.1/com.sun.xml.bind/jaxb-impl/2.3.0.1/2e979dabb3e5e74a0686115075956391a14dece8/jaxb-impl-2.3.0.1.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)

WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector

WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations

WARNING: All illegal access operations will be denied in a future release

Juni 25, 2019 2:34:05 NACHM. org.jooq.tools.JooqLogger error

SCHWERWIEGEND: Cannot read /home/elkemint/switchdrive/HLS/jpro/studentischeprojekte/build/tmp/generateSampleJooqSchemaSource/config.xml. Error : JavaFXGenerator

java.lang.ClassNotFoundException: JavaFXGenerator

at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)

at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)

at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)

at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:821)

at org.jooq.codegen.GenerationTool.run(GenerationTool.java:331)

at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:222)

at org.jooq.codegen.GenerationTool.main(GenerationTool.java:194)

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':generateSampleJooqSchemaSource'.

> Process 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' finished with non-zero exit value 255

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

1 actionable task: 1 executed

Process 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' finished with non-zero exit value 255

14:34:05: Task execution finished 'build'.

What is wrong?

The class IS included in the jar in the buildSrc/build-folder.

I also tried several package structures in buildSrc/main/java and got warnings that the class would not be found by the main script using the old package name, so it seems to be connected anyhow.

I would be really thankful for your advice.

Best greetings, Elke
```

---

<div class="post-metadata">

**Author:** ![Lance](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/lance/32/787_2.png) [@Lance](https://discuss.gradle.org/u/Lance)\
**Post date:** [June 25, 2019, 12:58pm UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/10 "2019-06-25T12:58:42Z")

</div>

Is JavaFXGenerator in a package? Is it a public class?

---

<div class="post-metadata">

**Author:** ![elkebasel](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@elkebasel](https://discuss.gradle.org/u/elkebasel)\
**Post date:** [June 25, 2019, 6:49pm UTC](https://discuss.gradle.org/t/custom-generator-class-not-found-by-jooq-codegen-plugin/32186/11 "2019-06-25T18:49:10Z")

</div>

Dear Lance

I now tried to generate my jooq classes without the plugin from Etienne Studer: generating an xml String for configuration and calling the GenerationTool.generate() Method with this xml String as argument.

When I put my custom generator as name tag in this xml, theclass (in buildSrc) ist found. So I have at least a workaround.

Best, Elke

Gesendet von [Mailspring](https://getmailspring.com/), der besten kostenlosen E-Mail-App für die Arbeit
