Annotation Processor in IntelliJ and Gradle : <p><strong>tl;dr</strong>: I cannot configure IntelliJ to generate the java files in the same directory as gradle</p>

<p>I have a small project which uses the <a href="https://immutables.github.io/" rel="noreferrer">immutables</a> annotation processor.
It works as expected in the gradle command line build, but I cannot get IntelliJ to output the generated files to the same directory.</p>

<p>The full project is available on <a href="https://gitlab.com/tmtron-immutables/encoding/tree/0.0.1" rel="noreferrer">GitLab</a></p>

<p><strong>Gradle config</strong>:<br>
I use the folowing gradle plugins:</p>

<ul>
<li><a href="https://docs.gradle.org/current/userguide/idea_plugin.html" rel="noreferrer">gradle-idea plugin</a> which handles the idea configuration</li>
<li><a href="https://github.com/tbroyer/gradle-apt-plugin" rel="noreferrer">gradle-apt-plugin</a> which provides the apt configuration and handles the compile-class path and idea config related to annotation processing (if also the idea plugin is applied)</li>
</ul>

<p>relevant parts of the build-script (<a href="https://gitlab.com/tmtron-immutables/encoding/blob/0.0.1/build.gradle" rel="noreferrer">link to the full listing</a>):</p>

<pre><code>apply plugin: 'java'
apply plugin: "net.ltgt.apt"
apply plugin: 'idea'

dependencies {
    def immutablesVersion = '2.3.9'
    compileOnly "org.immutables:value:$immutablesVersion:annotations"
    compileOnly "org.immutables:encode:$immutablesVersion"
    apt "org.immutables:value:$immutablesVersion"
}
</code></pre>

<p>when I start <code>./gradlew build</code> everything is as expected:
<a href="https://gitlab.com/tmtron-immutables/encoding/blob/0.0.1/build.gradle" rel="noreferrer"><img src="https://i.stack.imgur.com/Es3n0.png" alt="enter image description here"></a></p>

<ol>
<li>The source file <code>DataEncoding.java</code> is processed an the generated java-file <code>DataEncodingEnabled.java</code> ends up in</li>
<li><code>/build/generated/source/apt/main</code> under the expected package <code>com.tmtron.immutables.data</code></li>
<li>and the generated file is also compiled to a .class file</li>
</ol>

<p>In IntelliJ I activate the annotation processing as suggested by the <a href="https://github.com/tbroyer/gradle-apt-plugin#intellij-idea" rel="noreferrer">gradle-apt-plugin docs</a>:
<a href="https://github.com/tbroyer/gradle-apt-plugin#intellij-idea" rel="noreferrer"><img src="https://i.stack.imgur.com/bSSEx.png" alt="enter image description here"></a></p>

<p>Then I execute <code>./gradlew clean</code> to make sure, that the previous files are gone and then I click <code>Build</code> - <code>Build Project</code> in IntelliJ.<br>
The annotation processor is executed, but the problem is that the generated java file ends up in the wrong location:
<a href="https://i.stack.imgur.com/bSSEx.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2sc7u.png" alt="enter image description here"></a></p>

<p>It is in:   /build/generated/source/apt/main/<strong>build/generated/source/apt/main</strong>/com.tmtron.immutables.data<br>
the bold part is redundant.  </p>

<p>What am I doing wrong and how can I set it up correctly, so that IntelliJ and gradle generate the files in the same directory?</p>

<p>Notes: </p>

<ul>
<li>I have of course already tried to just leave the "Production sources dir" in the IntelliJ annotation configuration empty, but his does not work: then it automatically uses "generated" and I also end up with a wrong path.</li>
<li>IntelliJ version 2016.3.4</li>
</ul>
