如何在IDEA中定义Gradle的家?

本文翻译自:How to define Gradle's home in IDEA?

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 of Gradle Home result in a valid location - I have the GRADLE_USER_HOME environment variable set (to what I think is!) the correct path, and I have been able to successfully import this same project into Eclipse. 我正在尝试将Gradle项目导入IntelliJ,当我进入Gradle Home文本框时,它不会自动填充,也不会在Gradle Home的路径中键入有效的位置-我设置了GRADLE_USER_HOME环境变量(正确的路径,并且我已经能够成功地将同一项目导入Eclipse。 Any suggestions? 有什么建议么?


#1楼

参考:https://stackoom.com/question/1FbW6/如何在IDEA中定义Gradle的家


#2楼

AFAIK it is GRADLE_HOME not GRADLE_USER_HOME (see gradle installation http://www.gradle.org/installation ). AFAIK是GRADLE_HOME而不是GRADLE_USER_HOME(请参阅gradle安装http://www.gradle.org/installation )。

On the other hand I played a bit with Gradle support in Idea 13 Cardea and I think the gradle home is not automatically discover by Idea. 另一方面,我在Idea 13 Cardea的Gradle支持下发挥了一些作用,我认为Gradle的家并不是由Idea自动发现的。 If so you can file a issue in youtrack. 如果是这样,您可以在youtrack中提出问题。

Also, if you use gradle 1.6+ you can use the Graldle support for setting the build and wrapper. 另外,如果使用gradle 1.6+,则可以使用Graldle支持来设置构建和包装。 I think idea automatically discover the wrapper based gradle project. 我认为想法会自动发现基于包装的gradle项目。

$ gradle setupBuild --type java-library $ gradle setupBuild --type java-library

$ gradle wrapper $ gradle包装

Note: Supported library types: basic, maven, java 注意:支持的库类型:基本,maven,java

Regards 问候


#3楼

You can write a simple gradle script to print your GRADLE_HOME directory. 您可以编写一个简单的gradle脚本来打印GRADLE_HOME目录。

task getHomeDir {
    doLast {
        println gradle.gradleHomeDir
    }
}

and name it build.gradle . 并将其命名为build.gradle

Then run it with: 然后运行:

gradle getHomeDir

If you installed with homebrew, use brew info gradle to find the base path (ie /usr/local/Cellar/gradle/1.10/ ), and just append libexec . 如果安装了自制软件,请使用brew info gradle查找基本路径(即/usr/local/Cellar/gradle/1.10/ ),然后附加libexec

The same task in Kotlin in case you use build.gradle.kts : 如果您使用build.gradle.kts在Kotlin中执行相同的任务:

tasks.register("getHomeDir") {
    println("Gradle home dir: ${gradle.gradleHomeDir}")
}

#4楼

If you installed gradle with homebrew, then the path is: 如果您使用自制软件安装了gradle,则路径为:

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

Where XX is the version of gradle (currently 2.1) 其中XX是gradle的版本(当前为2.1)


#5楼

Installed on a Mac via Homebrew, the path 通过Homebrew安装在Mac上,路径

/usr/local/opt/gradle/libexec

is preferable to 优于

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

since the former will survive version upgrades. 因为前者将在版本升级后继续存在。


#6楼

我在无法找到我的班级的地方遇到了一些奇怪的错误,我必须右键单击src文件夹(呈红色),将其“设为目录”->源文件夹根

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章