所以我得到了这个gradle脚本,让我上传apx到Nexus。问题是这些文件最终没有服务器上的文件扩展名,如果你想从那里下载应用程序就会出现问题。
似乎我通过了正确的mime类型,但即便如此,我仍然会收到没有扩展名的文件。
以下是代码:
def uploadToRepository(File file,
String folder,
String url,
String userName,
String password){
HTTPBuilder http = new HTTPBuilder(url)
String basicAuthString = "Basic " + "${userName}:${password}".bytes.encodeBase64().toString()
http.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader('Authorization', basicAuthString)
}
})
try {
http.request(Method.POST, "application/vnd.android.package-archive") { req ->
uri.path = "/content/repositories/releases/${folder}"
MultipartEntity entity = new MultipartEntity()
def fileBody = new FileBody(file, "application/vnd.android.package-archive")
entity.addPart("file", fileBody)
req.entity = entity
response.success = { resp, reader ->
if(resp.status == 201) {
println "File ${file.name} uploaded"
}
}
}
} catch (Exception e) {
e.printStackTrace()
}
}