这是我第一次尝试使用clojure,我正在尝试在build.gradle文件中生成一些任务。我遇到了并发症错误,例如:
*其中:
构建文件'/Users/austin/Repositories/test/build.gradle'第47行
*出了什么问题:
评估根项目'test'时出现问题。 无法为任务设置只读属性'src'的值:download deriunder.fox.deascouch.gradle.tasks.download.Download的downloadDriverfirefox。
我很确定这只是我对groovy语言的经验不足,但我真的可以用一些指示来解决我出错的地方。
ext {
// The drivers we want to use
drivers = ["firefox", "chrome"]
driversSrc = [:]
driversSrc['firefox'] = 'https://github.com/mozilla/geckodriver/releases/download/v0.15.0/geckodriver-v0.15.0-macos.tar.gz'
driversSrc['chrome'] = 'https://chromedriver.storage.googleapis.com/2.29/chromedriver_mac64.zip'
driverDest = new File("${buildDir}/webdrivers")
}
import org.gradle.api.tasks.*
import de.undercouch.gradle.tasks.download.Download
driversSrc.each { driver, path ->
tasks.create(name: 'downloadDriver'+"${driver}", type: Download) {
src = path
dest ext.driverDest
overwrite true
}
}
driversSrc.each {driver ->
tasks.create(name: 'unzipDriver'+"${driver}", dependsOn: 'downloadDriver'+"${driver}", type: Copy) {
from zipTree(file('downloadDriver'+"${driver}").dest)
into buildDir/'webdrivers'
}
}
答案 0 :(得分:2)
我做过的事情:
tarTree
以及zipTree
请尝试:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "de.undercouch:gradle-download-task:3.2.0"
}
}
allprojects {
repositories {
jcenter()
}
}
import de.undercouch.gradle.tasks.download.Download
apply plugin: "de.undercouch.download"
ext {
driversSrc = [
"firefox": "https://github.com/mozilla/geckodriver/releases/download/v0.15.0/geckodriver-v0.15.0-macos.tar.gz",
"chrome" : "https://chromedriver.storage.googleapis.com/2.29/chromedriver_mac64.zip"
]
driverDest = "${buildDir}/webdrivers"
}
driversSrc.each { driver, path ->
def fileDest = new File(driverDest, new File(path).getName())
tasks.create(name: "downloadDriver${driver}", type: Download) {
src path
dest fileDest
overwrite true
}
tasks.create(name: "unzipDriver${driver}", dependsOn: "downloadDriver${driver}", type: Copy) {
from path.endsWith("zip") ? zipTree(file(fileDest)) : tarTree(file(fileDest))
into driverDest
}
}
运行任务:
./gradlew unzipDriverfirefox unzipDriverchrome*