build.gradle fails to compile on project open but compiles successfully after refresh
Answered
I've been looking around for a solution to this problem that's been going on for a lot of time and a lot of IntelliJ Idea versions and I'm surprised that I can't find anything on the matter.
What happens is, every time I open a Gradle project which has import statements in build.gradle, the validation on build.gradle will fail until I hit the Gradle refresh button. Then everything checks out, all the syntax gets properly highlighted and all errors and warnings are gone.
In the screenshot below you can see what it looks like.

Why is this happening and how can I have my build.gradle validate successfully when I open up the project without having to refresh every time?
Please sign in to leave a comment.
Please vote for this issue in our tracker: https://youtrack.jetbrains.com/issue/IDEA-232823
Migrating your projects to Android Studio requires adapting to a new project structure, build system, and IDE functionality. If you are migrating an Android project from Eclipse, Android Studio provides an import tool so you can quickly move your existing code into Android Studio projects and Gradle-based build files. For more information, see Migrating from Eclipse.
If you are migrating from IntelliJ and your project already uses Gradle, you can simply open your existing project from Android Studio. If you are using IntelliJ, but your project does not already use Gradle, you will need to do a little bit of manual preparation before you can import your project into Android Studio. For more information, see Migrating from IntelliJ.
Official Website: Professional Wikipedia Editors
I'm not migrating or importing the project from anywhere else.
The project has been created with IntelliJ. I'm simply closing and reopening the project and after reopening the project, build.gradle no longer validates successfully until I hit the Refresh button in Gradle.
It's a known and already reported issue as pointed out by Andrey Dernov
Please vote for it so it will be fixed.