[RESOLVED] Dynamically Loading Classes via Plugin

I’m having an issue running the jOOQ gradle plugin when specifying a custom class to be loaded by the jOOQ code generator, which fails with a ClassNotFoundException. I have put an example project that demonstrates the issue up on GitHub. You will need a Postgres installation with a DB and a role with the given credentials in build.gradle, which can then be tested by running gradle jar.

By my understanding, by loading a library in the buildscript section via classpath it should be available for the plugin to use. Of note, is that the Postgres driver is also loaded in the same block, and is loaded by the same code in jOOQ. I modified the jOOQ library to add some logging statements in the method that attempts to load my class, and it loads other classes just fine, which is really throwing me for a loop. I’ve checked the logs generate with the --debug switch and my JAR containing the custom generator class is picked up.

19:25:54.904 [INFO] [unknown.jul.logger] ===== Loading Class File
19:25:54.904 [INFO] [unknown.jul.logger] ===== Class Name: org.postgresql.Driver
19:25:54.905 [INFO] [unknown.jul.logger] ===== loader == null: true
19:25:54.906 [INFO] [unknown.jul.logger] ===== ClassLoader.loadClass: class org.postgresql.Driver
19:25:54.909 [INFO] [unknown.jul.logger] ===== Class.forName: class org.postgresql.Driver
19:25:54.910 [INFO] [unknown.jul.logger] ===== Thread: class org.postgresql.Driver
19:25:54.963 [INFO] [unknown.jul.logger] ===== Loading Class File
19:25:54.963 [INFO] [unknown.jul.logger] ===== Class Name: org.jooq.util.DefaultGenerator
19:25:54.964 [INFO] [unknown.jul.logger] ===== loader == null: true
19:25:54.968 [INFO] [unknown.jul.logger] ===== ClassLoader.loadClass: class org.jooq.util.DefaultGenerator
19:25:54.976 [INFO] [unknown.jul.logger] ===== Class.forName: class org.jooq.util.DefaultGenerator
19:25:54.976 [INFO] [unknown.jul.logger] ===== Thread: class org.jooq.util.DefaultGenerator
19:25:54.978 [INFO] [unknown.jul.logger] ===== Loading Class File
19:25:54.979 [INFO] [unknown.jul.logger] ===== Class Name: us.hexcoder.CustomJooqGeneratorStrategy
19:25:54.979 [INFO] [unknown.jul.logger] ===== loader == null: true
19:25:54.979 [INFO] [unknown.jul.logger] ===== Error load via ClassLoader.loadClass
19:25:54.980 [INFO] [unknown.jul.logger] ===== Error loading via Class.forName()
19:25:54.980 [INFO] [unknown.jul.logger] ===== Error loading via Thread

Any suggestions?

I could not link to the jOOQ code that attempts to load the class due to a rather short-sited restriction on the number of links a new user can post.

This is due to the particular way the JDBC loads drivers.

There’s a solution here: Jdbc driver class cannot be loaded with gradle 2.0 (but worked with 1.12)

I’m having the same issue, trying to assign a customized GeneratorStrategy using the jooq plugin.
I don’t see any relation to jdbc drivers here. How was this resolved?

class CustomJooqGeneratorStrategy extends DefaultGeneratorStrategy {
}

jooq {
    main(sourceSets.main) {
    ...
            strategy {
                name = CustomJooqGeneratorStrategy.class.canonicalName
            }
    }
}