I'm using Spring Boot 2.1.1 with jOOQ codegen tool 3.11.7. I have a Java class configured to slightly modify class names derived from MySQL table names in pom.xml:
<generator>
<target>
<packageName>com.example.foglight.db</packageName>
<directory>src/main/java</directory>
</target>
<database>
<excludes>
flyway_schema_history
| information_schema.*
</excludes>
<inputSchema>${dbName}</inputSchema>
<outputSchemaToDefault>true</outputSchemaToDefault>
<forcedTypes>
<forcedType>
<userType>java.util.UUID</userType>
<binding>com.example.foglight.config.db.MysqlUuidBinding</binding>
<types>BINARY\(16\)</types>
</forcedType>
</forcedTypes>
</database>
<generate>
<deprecationOnUnknownTypes>false</deprecationOnUnknownTypes>
<pojos>true</pojos>
</generate>
<!-- The default code generator. You can override this one, to generate your own code style
Defaults to org.jooq.codegen.JavaGenerator -->
<name>org.jooq.codegen.JavaGenerator</name>
<!-- The naming strategy used for class and field names.
You may override this with your custom naming strategy. Some examples follow
Defaults to org.jooq.codegen.DefaultGeneratorStrategy -->
<strategy>
<name>com.example.foglight.config.db.DatabaseModelNamingStrategy</name>
</strategy>
</generator>
Everything works fine when I'm building/running the app from IntelliJ, however when I run mvn generate-sources
or mvn install
from command line in the very same environment, I'm getting the following error:
[ERROR] Failed to execute goal org.jooq:jooq-codegen-maven:3.11.7:generate (default) on project foglight: Error running jOOQ code generation tool: com.example.foglight.config.db.DatabaseModelNamingStrategy -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jooq:jooq-codegen-maven:3.11.7:generate (default) on project foglight: Error running jOOQ code generation tool
With detailed explanation below:
Caused by: java.lang.ClassNotFoundException: com.example.foglight.config.db.DatabaseModelNamingStrategy
at java.net.URLClassLoader.findClass (URLClassLoader.java:471)
at java.lang.ClassLoader.loadClass (ClassLoader.java:588)
at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
at org.jooq.codegen.GenerationTool.loadClass (GenerationTool.java:819)
at org.jooq.codegen.GenerationTool.run (GenerationTool.java:352)
at org.jooq.codegen.GenerationTool.generate (GenerationTool.java:220)
at org.jooq.codegen.maven.Plugin.execute (Plugin.java:197)
The class is there (otherwise IntelliJ would be throwing the error too). Is there anything more that IDE is doing under the hood that makes it work?
The jOOQ code generator must have access to your generator strategy via the classpath, which means it has to have been compiled before you run the code generator. Since the code generator usually runs before the compilation phase of the Maven module that contains it, you will have to extract your generator strategy into another module to make sure it gets compiled before.