70

I can't find the Gradle Tool Window in IntelliJ IDEA 13 anymore. Is it removed?

Furthermore I can't run any Gradle Tasks within my Gradle build file (via context-menu -> Run). The error message: Module XY is not backed by gradle occurs. All these runs perfectly in IntelliJ IDEA 12.

What is going wrong here?

Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
GedankenNebel
  • 2,437
  • 5
  • 29
  • 39

11 Answers11

143

TL;DR

As of 2018.3.6:

  1. In the project tool window locate the build.gradle/build.gradle.kts file
  2. Right click the build file and select Link Gradle Project (or Import Gradle Project in some IntelliJ IDEA versions)

Background

In regards to the OP's question at the time when IDEA 13 was released, the Gradle Plugin was rewritten and improved in IntelliJ IDEA 13. As a result, Gradle based IDEA projects created in previous versions of IntelliJ IDEA needed to be reimported when first opened in IntelliJ IDEA 13.

Post IntelliJ IDEA 13, sometimes the Gradle Tool window will disappear if the IntelliJ IDEA Project gets out of sync or its configuration gets corrupted.

The Fix

IntelliJ IDEA 2018.3.6 or Later

The quick fix

  1. Find and select the build.gradle/build.gradle.kts file in the Project tool window
  2. Open the context menu (i.e. right click) and select Link Gradle Project or Import Gradle Project in some versions. (I'm not sure in which version the menu item name got changed.)

NOTE 1: If the context menu option is not available, then that typically means the Gradle Plugin got disabled or uninstalled. Go to Settings/Preferences > Plugins and enable or install the JetBrains Gradle plugin.

NOTE 2: If the gradle build can not be completed successfully, IntelliJ IDEA may not be able to sync to it properly. In such cases, you will likely need to get the gradle build working first.

When the Quick Fix does not work

While the above "Quick Fix" should work most of the time, if it does not work, you may need to:

  1. If not already done, try the above "Quick Fix". Proceed if that does not resolve the issue.
  2. Invalidate your caches via File > Invalidate Caches.
  3. Restart IntelliJ IDEA.
  4. Wait for the project to get re-indexed. (Watch the progress on right side of the bottom Status Bar of the IntelliJ IDEA window.)
  5. If the Gradle window does not show after indexing finishes, run the steps in the above "Quick Fix".
  6. The above steps should solve the issue in almost all cases. If not, close the project in IntelliJ IDEA. In the system, look for the gradle.xml file in the project's .idea directory. Delete or rename it. (If you have gotten to this point, it is most likely this file has been corrupted and we want IntelliJ IDEA to recreate it.) Then reopen the project in IntelliJ IDEA and run the quick fix.

IntelliJ IDEA Pre version 2018.3.6

First, see if the tool window can be opened via View > Tool Windows > Gradle. If so, the gradle project is configured and ready to use. If not, you will need to re-import the project as discussed below.

While your project settings should be maintained, it would be prudent to backup the .idea directory prior to doing the re-import. Go to File > Import Project (or File > New > Project from Existing Sources in newer IntelliJ versions), select and import your *.gradle file. You can choose "This Window" when prompted as to what window to open the project in. You will then have the Gradle window (renamed from JetGradle) and gradle functionality. All your previous project settings should remain intact. If not, close the project and do a diff of the backed-up and current .idea directories.

For some versions of IDEA, the above may not work if done with the project opened. Instead, you will need to close the project, and do the import from the Welcome Screen or another project. This also holds true if the project was never a gradle project and you want to add gradle functionality/backing.

Javaru
  • 30,412
  • 11
  • 93
  • 70
  • 8
    That's not cool. (but it may be the answer anyway) I want to move a many-module project to gradle. IMHO it should be possible to do handle this a module at a time. That's supposed to be one of the big improvements in 13... the ability to handle multiple modules each with their own gradle file. (previously if you added one it took over the WHOLE *project*, and pretty much trashed everything in the process) – Gus Jan 08 '14 at 17:58
  • The import does not succeed if the gradle project cannot be built. Is there a workaround for this? – jakk Oct 28 '14 at 13:15
  • 1
    @jakk - Without building properly, IDEA cannot extract the (correct) needed information it needs to configure itself. I think the closest thing to a workaround would be to isolate the code that is not allowing the project to build. Even if that means temporarily moving all code out, importing the gradle project, then moving the code back. – Javaru Oct 28 '14 at 14:01
56

IntelliJ have certainly had trouble solving this particular problem, but as of 2018.3.6 the solution has certainly gotten better:

  1. find the gradle.build file
  2. right-click on it and select Import Gradle Project

no idea (badoom tshhhh) why they've decided to do it this way, but it works, the Gradle tool window becomes available, and it has become a gradle project.

Michael Coxon
  • 3,337
  • 8
  • 46
  • 68
9

You can add a gradle.xml file in your .idea directory

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="GradleSettings">
    <option name="linkedExternalProjectsSettings">
      <GradleProjectSettings>
        <option name="distributionType" value="LOCAL" />
        <option name="externalProjectPath" value="$PROJECT_DIR$" />
        <option name="gradleHome" value="$USER_HOME$/.gradle" />
        <option name="gradleJvm" value="1.8.0_40" />
      </GradleProjectSettings>
    </option>
  </component>
</project>

This should enable the gradle panel to show up.

Make sure to replace the correct paths above

seantomburke
  • 10,514
  • 3
  • 18
  • 23
  • 1
    I don't know why the file was missing as I had several gradle projects imported but that was indeed the problem. – Martin Oct 15 '18 at 13:42
9

What helped me was File > Invalidate Chaches and Restart
After restarting the gradle menu was available

Simon Schnell
  • 1,160
  • 14
  • 24
8

This helped me: (In IntelliJ 2019.2.4)

  1. File -> Invalidate Caches/Eestart
  2. Right Click on your build.gradle in your Project in Project View -> At the bottom click on : Import Gradle Project
  3. View -> Tool Windows -> Gradle
bbrinck
  • 953
  • 1
  • 9
  • 33
7

In IntelliJ IDEA 2016.2.2 version, from main menu, try;

View->Tool windows-> Gradle

Update: For those who are downvoting, this answer gave the menu solution before the accepted answer.

myuce
  • 1,321
  • 1
  • 19
  • 29
  • Thanks you. There is no *File > Import Project* in 2016.2.2, so this helped. – Goodies Sep 15 '16 at 17:50
  • 2
    In 2016.1.4 I have no "Tool windows" entry. But I have a "Tools buttons". Clicking that makes a "Gradle" button appear in the margin. That button opens the Gradle pane. – Florian F Feb 21 '17 at 16:58
3

What is going wrong here?

The possible reason is that GRADLE_HOME environment variable points to the wrong location.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
  • How to set GRADLE_HOME such that IntelliJ can see it? I've set it in launchd.conf and bashrc. Do I need to restart my workstation (Mac Pro)? – Piko Apr 23 '15 at 22:56
  • @Piko, sorry I don't have any experience with OS X. [Will it help?](http://stackoverflow.com/questions/7501678/set-environment-variables-on-mac-os-x-lion) – naXa stands with Ukraine Apr 24 '15 at 06:03
0

see this Intellij IDEA bug and this support issue

radistao
  • 14,889
  • 11
  • 66
  • 92
0

It worked for me.Workaround is to close the cloned project, and then open the build.gradle/build.gradle.kts file as a project.

RAHUL KUMAR
  • 1,123
  • 11
  • 9
0

In IntelliJ 2019.3 I faced the same issue, in addition it was not recognizing Gradle projects when I imported them. I fixed it by doing this:

  1. Disable Gradle plugin
  2. Restart IntelliJ
  3. Enable Gradle plugin again
  4. Restart IntelliJ

Done!

enter image description here

swngstack
  • 51
  • 5
0

I'm using Intellij 2021.2.1 Ultimate. For me the following steps worked-

  1. Open plugin section under Settings.
  2. Enable Gradle plugin.
  3. Restart Intellij by invalidating caches
  4. Let Intellij complete the indexing

That's all.

Caffeine Coder
  • 948
  • 14
  • 17