task pushOSS {
doLast {
String endpoint = project.property("aliyun.oss.endpoint")
String accessKeyId = project.property("aliyun.oss.accessKeyId")
String accessKeySecret = project.property("aliyun.oss.accessKeySecret")
String bucketName = project.property("aliyun.oss.bucketName")
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret)
def listing = ossClient.listObjects(bucketName)
DeleteObjectsResult deleteObjectsResult = ossClient.deleteObjects(
new DeleteObjectsRequest(bucketName).withKeys(listing.objectSummaries.collect { it.key }));
println "Delete oss: " + deleteObjectsResult.deletedObjects.size()
fileTree("$buildDir/gitPublish").each { f ->
def targetName = f.path.substring("$buildDir/gitPublish".size() + 1)
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, targetName, f);
def result = ossClient.putObject(putObjectRequest)
println "Sync oss: " + targetName
}
ossClient.shutdown()
}
}