How to define Gradle's home in IDEA?

后端 未结 16 571
太阳男子
太阳男子 2020-12-04 04:37

I am trying to import a Gradle project into IntelliJ, and when I get to the Gradle Home textbox, it is not automatically populated, nor will typing in the path

相关标签:
16条回答
  • 2020-12-04 05:21

    I had some weird errors where it could not find my class, I had to right click on my src folder (was red) to "Make Directory as" -> Source Folder Root

    0 讨论(0)
  • 2020-12-04 05:21

    In case you are using Mac, most probably your gradle home should be /usr/local/gradle-2.0 for example.

    In preference of IDEA search for gradle and set gradle home as given above. It should work

    0 讨论(0)
  • 2020-12-04 05:22

    Installed on a Mac via Homebrew, the path

    /usr/local/opt/gradle/libexec
    

    is preferable to

    /usr/local/Cellar/gradle/X.X/libexec
    

    since the former will survive version upgrades.

    0 讨论(0)
  • 2020-12-04 05:24

    If you are using IntelliJ, just do the following.

    1. Close the project
    2. (re)Open the project
    3. you will see "Import gradle project" message on the right bottom. click.
    4. select "Use default gradle wrapper". not "Use local gradle distribution"

    That's all.

    0 讨论(0)
  • 2020-12-04 05:25

    This is instruction for MAC only. I had the same problem. I solved it by configuring $GRADLE_HOME in .bash_profile. Here's how you do it:

    • Open .bash_profile (usually it's located in the user’s home directory).
    • Add the following lines to update $PATH variable: export GRADLE_HOME=/usr/local/opt/gradle/libexec export PATH=$GRADLE_HOME/bin:$PATH
    • Save it.
    • Apply your changes by running source .bash_profile

    I wrote my own article with instruction in a case if somebody will encounter the same problem.

    0 讨论(0)
  • 2020-12-04 05:26

    You can write a simple gradle script to print your GRADLE_HOME directory.

    task getHomeDir {
        doLast {
            println gradle.gradleHomeDir
        }
    }
    

    and name it build.gradle.

    Then run it with:

    gradle getHomeDir
    

    If you installed with homebrew, use brew info gradle to find the base path (i.e. /usr/local/Cellar/gradle/1.10/), and just append libexec.

    The same task in Kotlin in case you use build.gradle.kts:

    tasks.register("getHomeDir") {
        println("Gradle home dir: ${gradle.gradleHomeDir}")
    }
    
    0 讨论(0)
提交回复
热议问题