我正在使用
Gradle version: 2.6
Groovy version: 2.3.10
运行gradlew idea
答案 0 :(得分:2)
代表Angle Tom:
使用针对旧版Groovy(由Gradle使用)配置的let request = NSMutableURLRequest(URL: NSURL(string: "http://example.com/login.php")!)
request.HTTPMethod = "POST"
let postString = "Username=Yourusername&password=Yourpassword"
request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding)
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in
guard error == nil && data != nil else { // check for fundamental networking error
print("error=\(error)")
return
}
if let httpStatus = response as? NSHTTPURLResponse where httpStatus.statusCode != 200 { // check for http errors
print("statusCode should be 200, but is \(httpStatus.statusCode)")
print("response = \(response)")
}
let responseString = String(data: data!, encoding: NSUTF8StringEncoding)
print("responseString = \(responseString)")
}
task.resume()
时发生强制转换错误。
在这种情况下,Gradle Idea插件的问题可能来自使用Groovy 1.8的pre-2.0 Gradle docs中的以下示例:
build.gradle
从Gradle 2.0开始,Groovy从1.8升级到2.3.2,如release notes中所述。 Groovy版本的主要突破意味着附加到列表的语法发生了变化。因此,Gradle文档updated反映了这一点:
idea {
module {
scopes.PROVIDED.plus += configurations.provided
}
}