Search code examples
intellij-ideagradle

No Gradle Tool Window in IntelliJ IDEA 13?


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?


Solution

  • 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.