Gradle工具安装及环境配置
Gradle工具下载:https://services.gradle.org/distributions/
一、下载
gradle-4.10.2-all.zip
https://downloads.gradle-dn.com/distributions/gradle-4.10.2-all.zip
二、环境配置
解压到这个目录:D:\6.CommonTools\gradle-4.10.2-all
将 D:\6.CommonTools\gradle-4.10.2-all\gradle-4.10.2\bin 添加到path
三、运行是否安装成功?
运行命令:gradle
D:\6.CommonTools\gradle-4.10.2-all\gradle-4.10.2\bin>gradle.bat Starting a Gradle Daemon (subsequent builds will be faster) FAILURE: Build failed with an exception. * What went wrong: Unable to start the daemon process. This problem might be caused by incorrect configuration of the daemon. For example, an unrecognized jvm option is used. Please refer to the user guide chapter on the daemon at https://docs.gradle.org/4.10.2/userguide/gradle_daemon.html Please read the following process output to find out more: ----------------------- Error occurred during initialization of VM Could not reserve enough space for 1048576KB object heap * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org
提示访问链接: https://docs.gradle.org/4.10.2/userguide/gradle_daemon.html
解决方法:
进入 C:\Users\用户名\.gradle 目录,手动新建一个文件:gradle.properties,gradle.properties文件内容添加 org.gradle.daemon=false 一行
再次打开cmd终端,运行ok,如下:
四、demo练习
创建一个文件:build.gradle,内容为:
// 定义hello1任务,传入的代码块负责配置该任务 task hello1 { println "配置第一个任务" }
输入:gradle build.gradle
虽然输出了,但是报了一个异常,如何解决?
通过下面方式运行:
先执行:gradle tasks
再执行:gradle build
运行后不会提示错误信息。