Help: IntelliJ IDEA doesn't recognize Gradle generated sources folder

I am using Gradle and AutoValue to generate sources for me, but IntelliJ IDEA doesn’t recognize the generated sources folder. I could find some links about this, but they are all from 2016, none worked for me, and I could see some people saying this doesn’t work anymore on the new versions of IntelliJ IDEA.

My code build fine in Gradle, but IntelliJ IDEA insist I have an error, since it doesn’t “see” the generated classes.

I tried already to:

  • Mark the generated source folder as a Generated Sources Root folder.
  • Mark the generated source folder as a source folder.
  • The idea plugin for gradle, as many suggested, like in here.
  • Disabling “Create separate module for source set”

None of this works.

How can I fix this?

Just to clarify, I have a root Gradle project ( main_project ), and 2 subprojects ( subproject_a and subproject_b ). The generated sources are inside one of the sub projects, under ../main_project/subproject_a/build/generated/sources/annotationProcessor/java/main/...

Here’s IntelliJ IDEA telling me there’s an error in my User class because it can’t find the generated source it uses, which is AutoValue_User (and the generated folder just right there):