36
votes

I have a toy Java project set up with Gradle in IntelliJ IDEA 13.1.2. It compiles and runs fine, but the IDE highlights 'google' in

import com.google.common.base.Strings;

as red and warns "Cannot resolve symbol 'google'". Any idea how to fix it?

I have tried 1) deleting .idea/ and re-creating the project in IntelliJ IDEA, and 2) re-importing project from the manually created Gradle configuration file build.gradle, but to no avail.

10
Look at the dependencies and artifacts of your IDEA project.PM 77-1
There is an "idea" plugin for gradle, see the question linked abovejzahedieh

10 Answers

45
votes

I think user Sap is correct, at least in my case. You should not have to manually add the dependency.

Did you change the dependencies in the gradle file without syncing intellij? Try this button:

screenshot of sync button

For more information, see: https://www.jetbrains.com/idea/help/synchronizing-changes-in-gradle-project-and-intellij-idea-project.html

13
votes

Check this.

You can simply open Gradle tool window at [ View ] - [ Tool Windows ] - [ Gradle ].

In the window, you can refresh by clicking refresh button.

All dependencies manually added directly into build.gradle file will be resolved.

9
votes

One of the solutions that worked for me after trying everything listed on the internet to solve this issue was to install the lombok plugin.

Got to File --> Settings --> Plugins and look for Lombok.

Make sure the "Enable annotation processing" is ticked

4
votes

My Gradle project is using Intellij 2019.2.3, and File->Invalid Cache/Restart... doesn't work, but View->Tool Windows->Gradle->sync(the circular icon) works instantly.

1
votes

It turns out that the depended packages need to be separately specified in IntelliJ IDEA in addition to build.gradle and explicitly added as a dependency. Namely,

  1. download the com.google.guava package following the instruction in documentation -- I picked com.google.guava:guava-base:r03 to download
  2. follow the automatically-prompted window to add it as a project library to the Java project.
  3. Specify that the Java module depends on the com.google.guava package in the project settings. See the documentation instruction "Configuring Module Dependencies and Libraries".
1
votes

In my case, I have to do the following:

  • close project
  • close idea
  • remove .idea project directory
  • remove (idea.system.path) directory
  • start idea

You can find your idea.system.path here: https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs

0
votes

In my case (Apache Beam sources) a ./gradlew clean was needed.

0
votes

In My Case, I've Updated the Gradle version(module: project) from 3.2.2 to 3.5.2, and also there was a problem with the NDK file location it was on the wrong path, I've just switched it to the default NDK path, then invalidate and restart the project.

0
votes

What helped me was checking "dependencies" in "project settings/modules" section. Apparently, Idea did not pick up them correctly.

Steps which worked for me:

  1. delete all modules from "project settings/modules"
  2. refresh the project from Gradle plugin - that triggers generation of modules

This trick helped me to get modules with correct dependencies generated. Probably it happened because initially, I imported the project as non-Gradle one.

0
votes

I was having the wrong import.Check if you have right import. In case you have imported using:

import org.junit.Test 

and you have org.junit.jupiter.api.Test in class path, try importing with :

import org.junit.jupiter.api.Test;