title: Gradle compile generated java file
body: <p>I'm trying to convert a big project to use <code>gradle</code> from the current state which uses <code>makefiles</code>.</p>
  
  <p>I have hit a wall though at some point. Suppose we have the following directory tree (a lot of stuff omitted for simplicity):</p>
  
  <pre><code>root
  |-- src
  |    +-- main
  |         +-- java
  |              +-- com
  |                  +-- app
  |                      |-- a
  |                      |-- b
  |                      +-- c
  +-- build.gradle
  </code></pre>
  
  <p>Now lets suppose that in package <code>com.app.c</code> exists a java file with a main class which is being used to generate a new java file under the same directory which then should be compiled as well. Package <code>com.app.c</code> has dependencies on the other packages as well.</p>
  
  <p>With a makefile you can do something like the following (a simple algorithm):</p>
  
  <ol>
  <li>Compile packages `com.app.a` and `com.app.c`.
  <li>Move to the directory of package `com.app.b` and compile only the files required to create the generated file.
  <li>Create the generated file by running the main function in the file used for generation.
  <li>Compile the whole `com.app.b` package which now includes the generated file.
  </ol>
  
  <p>Using gradle though I cannot do something like that (or at least I don't think I can).</p>
  
  <p>What I thought of doing was create a JavaExec task that will run the file that produces the generated java file and make it run after compileJava and also finalized with compileJava. But obviously that is a circular dependency between the tasks and a dead end.</p>
  
  <p>Has anyone ever done or met something similar? If anyone could help I would appreciate it.</p>
  
  <p>Note that I cannot easily move the file generation out of that file as it has some deep dependencies...</p>