繁体   English   中英

"为什么 gradle 不在 IntelliJ IDEA 的终端窗口中运行?"

[英]Why does gradle not run in the Terminal Window in IntelliJ IDEA?

当我在 IntelliJ IDEA 中打开终端窗口( View -> Tool Windows -> Terminal )并输入gradle tasks时,我会看到:

C:\Sathyaish\MyJavaAndSpringBootProject>gradle tasks
'gradle' is not recognized as an internal or external command,
operable program or batch file.

我推测 IntelliJ IDEA 显示Gradle工具窗口( View -> Tool Windows -> Gradle )以及 IDE 能够运行 gradle 任务并列出 gradle 依赖项的事实,IDE 自动在我的机器。

我在我的机器上搜索了一个gradle文件夹,该文件夹也有一个bin目录,但找不到。 我知道还没有自己安装 gradle。

我确实在 IntelliJ IDEA 安装文件夹中找到了一个gradle文件夹:

C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.1\plugins\gradle>dir /b
lib

C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.1\plugins\gradle>dir lib /b
commons-io-2.2.jar
commons-lang-2.6.jar
gradle-base-services-3.5.jar
gradle-base-services-groovy-3.5.jar
gradle-cli-3.5.jar
gradle-core-3.5.jar
gradle-jps-plugin.jar
gradle-logging-3.5.jar
gradle-messaging-3.5.jar
gradle-model-core-3.5.jar
gradle-model-groovy-3.5.jar
gradle-native-3.5.jar
gradle-process-services-3.5.jar
gradle-resources-3.5.jar
gradle-tooling-api-3.5.jar
gradle-tooling-extension-api.jar
gradle-tooling-extension-impl.jar
gradle-version-info-3.5.jar
gradle-wrapper-3.5.jar
gradle.jar
guava-jdk5-17.0.jar
jansi-1.14.jar
kryo-2.22.jar
minlog-1.2.jar
native-platform-0.14.jar
native-platform-freebsd-amd64-libcpp-0.14.jar
native-platform-freebsd-amd64-libstdcpp-0.14.jar
native-platform-freebsd-i386-libcpp-0.14.jar
native-platform-freebsd-i386-libstdcpp-0.14.jar
native-platform-linux-amd64-0.14.jar
native-platform-linux-amd64-ncurses5-0.14.jar
native-platform-linux-amd64-ncurses6-0.14.jar
native-platform-linux-i386-0.14.jar
native-platform-linux-i386-ncurses5-0.14.jar
native-platform-linux-i386-ncurses6-0.14.jar
native-platform-osx-amd64-0.14.jar
native-platform-osx-i386-0.14.jar
native-platform-windows-amd64-0.14.jar
native-platform-windows-i386-0.14.jar
objenesis-1.2.jar
reflectasm-1.07.jar
resources_en.jar

C:\Program Files\JetBrains\IntelliJ IDEA 2017.2.1\plugins\gradle>

如何运行命令gradle tasks以从 IntelliJ IDEA终端窗口中列出所有 gradle 任务? 我应该将C:\\Program Files\\JetBrains\\IntelliJ IDEA 2017.2.1\\plugins\\gradle\\lib 添加到我机器上的PATH环境变量中吗?

IntelliJ使用您在IntelliJ设置中指定的gradle wrappergradle distributed location

但是当您使用终端窗口时,它使用您的本机操作系统命令行,
因此,如果您没有在PATH环境变量中配置gradle,那么它将无法工作,因为它不是什么gradle。

将gradle添加到您的路径中:

视窗

In File Explorer right-click on the This PC (or Computer) icon, then click
 Properties -> Advanced System Settings -> Environmental Variables.

Under System Variables select Path, then click Edit. 
Add an entry for C:\Gradle\gradle-3.5\bin. Click OK to save.

Linux / Mac

export PATH=$PATH:/opt/gradle/gradle-3.5/bin

您应该将包含gradle.bat的目录添加到PATH并重新启动IntelliJ IDEA。

完整路径可能如下所示: d:\\dev\\gradle-3.5\\bin

如果您使用 gradle 启动 IntelliJ 项目,它会在项目的根目录中放置一个独立的 gradle 包装器 ( gradlew )。 您可以通过键入gradlew而不是gradle从终端访问它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM