Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does jOOQ suggest to put generated code under "/target" and not under "/src"?

Looking at the jOOQ example of the Maven plugin configuration for the code generator (near the end of the configuration), I see that the target directory for the generated files is target/generated-sources/jooq.

Since the generator produces Java code, do you know why the suggestion here isn't a subfolder of /src, but instead a completely separated one? Is there any reason for this? Is it a best practice or something?

like image 946
watery Avatar asked Aug 29 '14 21:08

watery


1 Answers

This is a good question and should probably also be covered in the jOOQ manual!

The question is not strictly related to jOOQ but to source code generation in general (e.g. also when using XJC to generate JAXB-annotated Java code from XSD). Some people prefer making generated source code part of the "main" source code, others prefer to keep it apart. There are essentially these ideas behind each approach:

Keeping things separate (e.g. target/generated-sources)

  • The only "source of truth" is the database schema. No copies thereof are ever stored in source form, only in binary form.
  • Source code generation becomes an integral part of your build. Everyone building your application (developers, continuous integration) will need to re-generate the sources. This will ensure that sources are always up to date.

Keeping things together (e.g. src/main/java)

  • The same "truth" is duplicated between the database schema and the generated copies thereof.
  • Source code generation is an "external" process, that isn't part of your build.
  • Generated sources are put under version control, where they are expected to be up-to-date.
  • Such version-controlled sources can be monitored for database changes, in the case of jOOQ.

There isn't really a generally preferred way. Both have their advantages.

like image 84
Lukas Eder Avatar answered Oct 24 '22 17:10

Lukas Eder