現(xiàn)象
1、build.gradle 內(nèi)容
task hello {
doLast {
println 'Hello, World!'
}
}
2、執(zhí)行g(shù)radle hello報(bào)錯(cuò)如下
D:\Work\gradle\test1>gradle hello
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\Work\gradle\test1\build.gradle' line: 1
* What went wrong:
A problem occurred evaluating root project 'test1'.
> Could not find method hello() for arguments [build_cns7om9rswrmisj5dav3jh63j$_run_closure1@119c2fee] on root project 'test1' of type org.gradle.api.Project.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
解決過(guò)程
使用環(huán)境:win10,JDK8,Gradle 3、4
通過(guò)google、baidu嘗試搜索各種關(guān)鍵字貌似都沒(méi)有類(lèi)似問(wèn)題,查詢(xún)gradle官網(wǎng)user guide一步一步操作問(wèn)題依舊。但始終懷疑跟環(huán)境有關(guān),于是搭建了一個(gè)centos的虛擬機(jī),在里面按照相同的方法操作居然沒(méi)有任何問(wèn)題,再將同樣的build.gradle文件拷貝到本地執(zhí)行也成功了。
通過(guò)記事本對(duì)比發(fā)現(xiàn)雖然文件內(nèi)容一樣,但之前在win10上采用的utf8的編碼,centos上拷貝過(guò)來(lái)的是ansi格式,原因終于找到了。
解決辦法
將build.gradle的編碼設(shè)置成unicode和ansi都可以,就是不能用utf8編碼格式。