心路历程:
//https://stackoverflow.com/questions/35050610/can-a-gradle-copy-task-be-used-to-copy-a-file-from-a-url
//https://plugins.gradle.org/plugin/org.ysb33r.vfs
Issue:
HEAD method failed for "https://hostname/repository/download/AndroidProjects/UPP/app/build/outputs/mapping/mapping.txt" with HTTP status 401.
Resolve:
Work well.
//in root build.gradle
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
//https://plugins.gradle.org/plugin/org.ysb33r.vfs
classpath 'org.ysb33r.gradle:vfs-gradle-plugin:1.0.1'
classpath 'commons-httpclient:commons-httpclient:3.1' // If you want http/https
}
}
// in host app build.gradle
plugins {
...
id 'org.ysb33r.vfs'
}
task downloadMyFile {
vfs {
cp 'https://username:password@hostname/repository/download/MobileAndroid/app/build/outputs/mapping/mapping.txt', new File("${buildDir}/myDownLoadDir/README.md"),overwrite:true
}
}
//setting.gradle
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
jcenter() //must
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
....
另一种方式:
task downloadMYFile(type: Exec) {
try {
def storeDir = "$buildDir\\a"
mkdir(storeDir)
workingDir "$storeDir"
//specified the ‘workingDir’ first ,it will skip or resolve permiss denied issue.
def command = "curl -O https://username:password@domain.com:443/devops-tools/latest/manifest.json"
def platform = System.getProperty("os.name").toLowerCase(Locale.ROOT)
println "curl start $platform==>$command"
if (platform.contains("windows")) {
commandLine 'cmd', '/c', "$command"
} else {
commandLine 'bash', '/c', "$command"
}
println "curl end==> ${out.toString()}"
} catch (Exception e) {
println "curl exception"
println "${e.getMessage()}"
e.printStackTrace()
}
}
以上方式目前实验下来只支持文件下载,并不支持文件夹下所有东西下载,后面研究了再更新
-----------------------------End-----------------------------
网友评论