Cannot resolve symbol from gradle's buildSrc

Answered

For some reason classes under gradle's buildSrc are not recognized in main build.gradle using idea editor. Classes are visible for build script though.

What can be wrong with installation/configuration?

N.B:

Restart/invalidate caches/reimporting/fresh new projects not working.

Gradle version: 6.5

IntelliJ IDEA 2020.2.1 (Community Edition)
Build #IC-202.6948.69, built on August 25, 2020
Runtime version: 11.0.8+10-b944.31 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 2014M
Cores: 4
Non-Bundled Plugins: Lombook Plugin, mobi.hsz.idea.gitignore, org.jetbrains.kotlin

0
25 comments

Can not reproduce

Could you please provide a test project and IDE logs (Help | Collect Logs and Diagnostic Data action)?

0
Avatar
Permanently deleted user

Yep forget to mention it's not reproducable on other machines.

logs

test project

0

Thank you. See no issues in logs. Please try with custom plugins disabled: Loaded custom plugins: Lombok (0.31-2020.2), .ignore (3.2.3.202)

Please try also the version from https://www.jetbrains.com/idea/download

0
Avatar
Permanently deleted user

Removed every bit of jetbrains products i've found: Idea, PyCharm, %USERPROFILE%/AppData/roaming/JetBrains folder, C:\Program Files\JetBrains folder and all ide related folders in %USERPROFILE% directory (old config dirs  I presume).

Maked new installation with ideaIC-2020.2.1 without any custom plugins....

Created brand new project in empty dir by hands (without Idea) with following structure:

build.gradle

buildSrc\

buildSrc\build.gradle

buildSrc\src\main\java\foo\Bar.java

 

Imported project and tried to use foo.Bar in build.gradle. Still can't resolve symbol.

0
Avatar
Permanently deleted user

Tried with 2018 and 2020.2.1 versions on Linux. Works just fine.

Moved projects to 2020.2.1 on my current Windows intallation - still non resolvable symbol.

That's really annoying.

Also tried removing .gradle folder, changed all config folders locations in "<Install folder>\bin\idea.properties" to the new folders, tried different jdks (idk why but why not)...

0

Thank you for the information. Could be some new regression. There was similar report created recently: https://youtrack.jetbrains.com/issue/IDEA-250256

Could you try if it help to start with all the defaults (File | Manage Settings | Restore Default Settings... action)?

0

Сould you please check this with the IDE Kotlin plugin disabled - does it help?

0
Avatar
Permanently deleted user

I seem to experience similar issue, I had no luck with the above suggestions.

1
Avatar
Permanently deleted user

I'm also experiencing the same issue starting from Intellij Idea 2020.2 (was reproducible on 2020.2.1 and still reproducible on 2020.2.2). Things work as they should if I use 2020.1.x. I noticed that in 2020.2.x you introduced a new code analyzer in the editor that is different from 2020.1.x. The old one didn't cause the issue discussed. Disabling Kotlin doesn't seem to help.

Perhaps it could help to spot the cause: I use Windows 10 May 2020 Update that was (and, possibly, still is) considered problematic for certain amount of software. Below I'll provide the screenshots, how the test project, uploaded here, looks in different versions of IntelliJ IDEA.

2020.2.2
IntelliJ IDEA 2020.2.2 (Community Edition)
Build #IC-202.7319.50, built on September 15, 2020
Runtime version: 11.0.8+10-b944.31 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 725M
Cores: 8
Non-Bundled Plugins: com.carbonblack.intellij.rpmspec, com.jetbrains.CyanTheme, net.sjrx.intellij.plugins.systemdunitfiles

2020.1.4
IntelliJ IDEA 2020.1.4 (Community Edition)
Build #IC-201.8743.12, built on July 21, 2020
Runtime version: 11.0.7+10-b765.65 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 725M
Cores: 8
Non-Bundled Plugins: com.carbonblack.intellij.rpmspec, org.jetbrains.kotlin, com.jetbrains.CyanTheme, net.sjrx.intellij.plugins.systemdunitfiles

0

We have fixed the issue. The fix will be available in the 2020.2.2+ version updates. Sorry for the inconveniences.

0

I was having this problem but then the upgrade to 2020.2.3 fixed it (after doing an invalidate caches/restart).

It was definitely working on all the sub-project scripts in my gradle build.

But recently I noticed the "cannot resolve symbol" has actually come back on some of them (but this time for non-buildSrc classes).

 

Invalidate/restart wasn't fixing it.  I deleted my ".../.IntelliJIdea/system" directory and restarted and now all seems fine.

0
Avatar
Permanently deleted user

Idea-shorn, where is the ".../.IntelliJIdea/system"  directory?

On Windows 10, I searched in the project directory, the IntelliJ Idea installation dir, and under 'USERPROFILE'. I have his issue, and I would like to try deleting the contents.

Thanks!

 

0

It's different on different OS's - no idea where it is on Windows 10.

https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs

That page indicates it should be under .../AppData/Roaming

0
Avatar
Permanently deleted user

I used File | Invalidate caches and Restart. That has not worked yet.

I read the descriptions documented under the link.  For my build of Idea 2020.2.3, there is a directory %USERPROFILE%\Roaming\JetBrains\IdeaIC2020.2. There are several directories there, but none called "system" are found when I do a recursive search. Its not obvious that any of the dirs below are a class cache. I would rather not destroy my entire setup.

d---- 8/30/2020 11:25 AM codestyles
d---- 8/30/2020 11:25 AM colors
d---- 8/30/2020 12:43 PM extensions
d---- 8/30/2020 11:25 AM inspection
d---- 8/30/2020 11:25 AM keymaps
d---- 10/21/2020 5:43 PM options
d---- 10/21/2020 2:42 PM plugins
d---- 8/30/2020 11:25 AM scratches
d---- 8/30/2020 11:27 AM ssl
d---- 9/21/2020 1:32 PM tasks
d---- 10/18/2020 9:45 AM templates
d---- 8/30/2020 11:25 AM terminal
d---- 10/21/2020 5:43 PM workspace

"workspace" is not documented on the reference page. Its purpose is not obvious.

 

0

@...

%USERPROFILE%\Roaming\JetBrains\IdeaIC2020.2 is the configuration directory. 

The system directory is C:\Users\JohnS\AppData\Local\JetBrains\IntelliJIdea2020.2 (pay attention that it is local AppData, not roaming).

By the way, the system directory is being cleaned on reset settings (File | Manage IDE Settings | Restore Default Settings)

0
Avatar
Permanently deleted user

Success!

I used File | Invalidate caches and Restart | Invalidate

Then, I moved %USERPROFILE%\AppData\Local\JetBrains\IdeaIC2020.2 to IdeaIC2020.2_bak

And started IDEA. IDEA rebuilt everything, and when it was finished, buildSrc classes were correctly resolved in the gradle editor.

Thanks folks!

 

1

It appears this is only a temporary fix though. 

I noticed the other day that the error started happening again (on many different packages, not just on `buildSrc` packages).

I tried clearing the system directory again and it seemed to work again (red squiggles gone, and Ctrl+Space completion working) - but then I restarted IDEA and the red squiggles were back (and Ctrl-Space not working on those packages).

So it looks like there might be some kind of corruption in IDEA's index/cache of Gradle stuff.

0

@Idea-shorn your problem seems different from initially reported, so need more details on it. Please file an issue at https://youtrack.jetbrains.com/issues/IDEA or a support request at https://intellij-support.jetbrains.com/hc/en-us/requests/new with all logs zipped (Help | Collect Logs and Diagnostic Data action) right after problem happens and screenshots describing the problem (as it is not clear when it happens - in groovy build scripts or in source code etc).

0
Avatar
Permanently deleted user

Like @Idea-shorn, I have found that deleting $ENV:USERPROFILE\AppData\Local\JetBrains\IdeaIC2020.2 is only a temporary fix, and that it must be done before every start of IDEA.

Has a new bug been filed?

 

0

@... This issue has been discussed in the scope of https://youtrack.jetbrains.com/issue/IDEA-250256.

Should have been fixed in EAP version of IntelliJ IDEA and backported to 2020.2.3. 

If it is not the case for you, please submit a new ticket and share the link here

0
Avatar
Permanently deleted user

I thought this issue was unchanged in IDEA64 2020.3.  But I left a buildSrc project open while I left my desk for lunch, and when I came back in an hour, the references had resolved. So on my 12 core 16gb workstation running Win 10, it takes between 5 minutes and 1 hour to resolve the dependencies from the 6 classes in buildSrc.

This project has 11 sub-projects, at 3 levels of depth. The buildSrc is only at the top. I'm considering creating a demo gradle project to further diagnose.

0

>it takes between 5 minutes and 1 hour to resolve the dependencies from the 6 classes in buildSrc.

The IDE completes the resolve short after the project has been imported in IDE. If it takes longer time it must be a different issue. Please file a bug at https://youtrack.jetbrains.com/issues/IDEA with a sample project, screenshots and all logs zipped (Help | Collect Logs and Diagnostic Data action) after problem occurs. A sample project would be very very helpful to have. Thank you.

0

I still have this exact issue even today. E.g.

Class GradleHelper is implemented in buildSrc/src/main/groovy/com/rockwell/library/gradle/commons/utils/GradleHelper.groovy
IntelliJ cannot resolve symbol GradleHelper in buildSrc/src/main/groovy/buildlogic.installer-conventions.gradle
Gradle runs without issue - just IntelliJ doesn't resolve.  Any ideas?


IntelliJ IDEA 2025.2.3 (Community Edition)
Build #IC-252.26830.84, built on October 2, 2025
Source revision: ba2aff1f71476
Runtime version: 21.0.8+1-b1038.72 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.windows.WToolkit
Windows 11.0
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4058M
Cores: 24
Registry:
 ide.experimental.ui=true
 llm.show.ai.promotion.window.on.start=false
Non-Bundled Plugins:
 com.intellij.notebooks.core (252.26830.93)
 com.github.mikesafonov.jenkins-linter-idea-plugin (0.6.0)
 com.intellij.properties (252.26830.93)
 org.toml.lang (252.26830.93)
 intellij.jupyter (252.26830.93)
 org.jetbrains.plugins.github (252.26830.99-IU)
 org.jetbrains.plugins.gitlab (252.26830.99-IU)
 org.jetbrains.security.package-checker (252.26830.95)
 com.intellij.tasks (252.26830.102)
 com.github.copilot (1.5.58-243)
Kotlin: 252.26830.84-IJ
 

0

Hi shaertel 

The main root cause for this problem is that IntelliJ IDEA builds a separate model for Gradle script editors. For Groovy precompiled script plugins located in buildSrc, the IDE sometimes does not include the compiled buildSrc main classes (e.g., com.rockwell.library...GradleHelper) on the script's editor classpath. Gradle itself compiles in the correct order (classes first, then the precompiled plugin), but the IDE's project model can lag behind or omit that relationship, leading to unresolved references in the editor even though the build is correct.

This is an IDE modeling/indexing limitation specific to Groovy precompiled script plugins in buildSrc referencing other buildSrc sources. So we already have a YouTrack issue reporting this bug, you can upvote and subscribe to it to receive updates, ticket ID is IDEA-270964.

Meanwhile this behavior is fixed you can try the next workarounds based on your constraints:

  1. Convert to a conventional Gradle plugin in buildSrc (recommended for IDE stability)
    1. Apply java-gradle-plugin in buildSrc and create a plugin class (e.g., class InstallerConventionsPlugin implements Plugin<Project> { ... }).
    2. Move logic from the precompiled script plugin into that class.
    3. IntelliJ generally resolves such project sources reliably.
  2. Switch to Kotlin DSL for the precompiled script plugin
    1. Use buildlogic.installer-conventions.gradle.kts instead of .gradle.
    2. Kotlin DSL precompiled plugins tend to have better IDE classpath wiring.

Please let me know if this works for your case.

1

.. wonderful - thanks, Monica! Will keep an eye on IDEA-270964.

0

Please sign in to leave a comment.