The obvious solution (code generation after the compilation phase) does not work, since Maven does not allow changing the phase order.
The correct solution is to use modules . You need two: the first module contains a code generator. In the second module, you can use the generator from the first module to generate something in the generate-sources phase.
The big advantage of this approach: you can never get into any kind of loop (for example, โAโ needs the generated code that needs โAโ). This way, your build will be simpler and you will spend less time looking for odd bugs.
[UPDATE] In my projects, I run the code generator from the tests. Without a special option, files are created in the temp folder and compared with sources. This allows me to see when I unexpectedly changed my generated code ( which I installed under version control ).
When the system property is set, the source files are overwritten, and I can commit the changes to my VCS.
source share