I have been trying to find the correct settings for IntelliJ's annotation processing in order for it to co-exist with Gradle's build process.
Whenever I build from IntelliJ I cannot get it to recognise the generated sources from the gradle-apt-plugin.
My requirements for my project are:
Here are the steps for a MCVE in order to reproduce the issue with IntelliJ 2017.2.4 and Gradle 3.5:
plugins
block:plugins {
id 'java'
id 'net.ltgt.apt' version '0.12'
}
dependencies
blockdependencies {
compileOnly 'com.google.auto.value:auto-value:1.5'
apt 'com.google.auto.value:auto-value:1.5'
}
@AutoValue
public abstract class GeneratedSourcesTest {
static GeneratedSourcesTest create(String field) {
return new AutoValue_GeneratedSourcesTest(field);
}
public abstract String field();
}
GeneratedSourcesTest
class, on the static factory method, everything compiles fine but I get the error:cannot resolve symbol ‘AutoValue_GeneratedSourcesTest’
How can I make the AutoValue_GeneratedSourcesTest
class accessible from IntelliJ?
After importing your Gradle project under IDEA do the following steps:
Run menu: Build - Build Project
Right click on each new generated folder and select: Mark Directory as - Generated Sources Root so it was marked as follows:
/generated
to project's .gitignore fileThat's a minimal viable configuration which will provide full IDE support for generated classes. The drawback is, whenever Gradle project gets re-imported the generated folders will need be marked as Generated Sources Root again. Perhaps this can be improved with adding these paths as source sets under build.gradle.
Sometimes it happens that IDEA modules lose their compiler output path settings in result of the above. It's sufficient to just set it back to their default folders.