本文翻譯自: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文件夾(呈紅色),將其“設爲目錄”->源文件夾根