gradle错误“无法将提供的表示法转换为文件或URI”

时间:2015-03-16 22:45:32

标签: gradle

我在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中的错误,还是我错过了什么?

1 个答案:

答案 0 :(得分:2)

此错误是由您的Gradle构建脚本委托给Project接口的实例引起的,该接口还有一个名为delete的方法,其参数由Project.file()评估。如果您想使用Ant任务,则必须使用ant前缀对其进行限定。