現(xiàn)象
1谁撼、build.gradle 內(nèi)容
task hello {
doLast {
println 'Hello, World!'
}
}
2并鸵、執(zhí)行g(shù)radle hello報錯如下
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
解決過程
使用環(huán)境:win10,JDK8放刨,Gradle 3每瞒、4
通過google沉颂、baidu嘗試搜索各種關(guān)鍵字貌似都沒有類似問題,查詢gradle官網(wǎng)user guide一步一步操作問題依舊欠窒。但始終懷疑跟環(huán)境有關(guān)覆旭,于是搭建了一個centos的虛擬機(jī),在里面按照相同的方法操作居然沒有任何問題岖妄,再將同樣的build.gradle文件拷貝到本地執(zhí)行也成功了型将。
通過記事本對比發(fā)現(xiàn)雖然文件內(nèi)容一樣,但之前在win10上采用的utf8的編碼荐虐,centos上拷貝過來的是ansi格式七兜,原因終于找到了。
解決辦法
將build.gradle的編碼設(shè)置成unicode和ansi都可以福扬,就是不能用utf8編碼格式腕铸。