问题
My question is what is the best way to set up my build using gradle and jooq with the following constraints:
I have:
- A very basic gradle build file, but one that can use eclipse, jooq, postgres and HSQL
- Some 'core' java classes, including a couple of Enums, in an eclipse project managed by gradle
- Several database schemata, each in its own file (schema1.sql, schema2.sql, etc), in that same project
- The most excellent JOOQ library, and the quite cool SQLFile utility from HSQLDB
- A combination of ANT scripts and java programs that do the following steps, in a pretty handraulic fashion, and which I'd like to automate.
I want the following functionality managed by gradle:
- The core classes are compiled
- Each of the database schema to be loaded into a postgres database (I know how to do this in gradle)
- The JOOQ library to generate classes from each schema (I know how to do this in gradle) using type mapping to map some database columns to appropriate core class Enums (I don't yet know how to do this in gradle, because I don't know how to give the JOOQ task access to the core classes)
There appear to be several options in front of me, but I'm not really sure which one would be the best:
- Option One: split the project into two projects, "core" and "db", the former being used by the latter to do the column-to-enum mappings, and downstream projects depending on both
- Option Two: keep one project, but split up the generation into three steps "compile core", "generate classes", "compile generated classes", where each step has access to the generated artefacts of the previous. But I don't really know how to do this.
I think that I can probably work out how to do either, given enough time, but I'm really wondering if this is a solved problem, and there's an obvious or canonical way to do it. For the record, my preference is Option Two, because this pattern recurs with other projects, and Option One will double the number of projects I have to deal with. (Maybe this isn't so bad...)
Sorry if this is a vague question - the documentation of gradle is actually pretty good from a "this is how to do X" point of view, but I don't really feel like I'm getting a good overview of how all the bits hang together.
I most appreciate any help.
EDIT
I have a related question which is the specifics of how to do Option 2. That question and answer are here Gradle: assembling multiple source-sets into one jar
While that question and answer describe how to do option two, they don't answer the broader question of "is this is best way to go about it", so I'm leaving this question open.
来源:https://stackoverflow.com/questions/27244262/jooq-class-generation-and-gradle