我在gradle.properties中定义了两个系统属性:
systemProp.buildDir=build
systemProp.cfgDir=build\\cfg
我在build.gradle中定义了以下任务:
task clean(group:'clean',description:'clean the project') << {
ant.sequential {
delete(dir: System.properties.buildDir)
mkdir(dir: System.properties.buildDir)
delete(dir: System.properties.cfgDir)
mkdir(dir: System.properties.cfgDir)
}
}
这会产生以下错误:
Execution failed for task ':clean'.
> Cannot convert the provided notation to a File or URI: {dir=build}.
The following types/formats are supported:
- A String or CharSequence path, e.g 'src/main/java' or '/usr/include'
- A String or CharSequence URI, e.g 'file:/usr/include'
- A File instance.
- A URI or URL instance.
但是这个等效的代码块不会产生任何错误并按预期工作:
task clean(group:'clean',description:'clean the project') << {
ant.delete(dir: System.properties.buildDir)
ant.mkdir(dir: System.properties.buildDir)
ant.delete(dir: System.properties.cfgDir)
ant.mkdir(dir: System.properties.cfgDir)
}
第一个语法的错误是gradle中的错误,还是我错过了什么?
答案 0 :(得分:2)
此错误是由您的Gradle构建脚本委托给Project
接口的实例引起的,该接口还有一个名为delete
的方法,其参数由Project.file()
评估。如果您想使用Ant任务,则必须使用ant
前缀对其进行限定。