gpt4 book ai didi

gradle - 如何使用 'dependsOn'如何执行Zip类型的任务?

转载 作者:行者123 更新时间:2023-12-03 05:09:04 25 4
gpt4 key购买 nike

我试图使我的任务zipGui在构建目标上执行,但是我似乎能够执行任务的唯一方法是从任务定义中删除(type: Zip)

此代码段根本无法执行zipGui任务:

task zipGui(type: Zip) {
doFirst {
println "==================== Zipping GUI components"
}

doLast {
FileTree zip = zipTree('assets/htdocs/gui.zip')
from 'assets/htdocs'
}
}


build.dependsOn zipGui

这会执行 zipGui,但对如何压缩文件一无所知:
task zipGui {
doFirst {
println "==================== Zipping GUI components"
}

doLast {
FileTree zip = zipTree('assets/htdocs/gui.zip')
from 'assets/htdocs'
}
}


build.dependsOn zipGui

这是整个 build.gradle的精简片段。

如何获得 zipGui作为构建的依赖项执行?

编辑:这是更多真正的 build.gradle,而无需我剥离内容以简化问题:
  task copyCert(type: Copy) {
from '../../../install'
into 'assets/certs/root'
include 'ca.pem'

doFirst {
println "==================== Copying root cert into assets"
}
}


task copyGui(dependsOn: copyCert, type: Copy) {
from '../../web/gui'
into 'assets/htdocs'
include '**/*.html'
include '**/*.css'
include '**/*.js'
include '**/*.wav'
include '**/*.tmpl'
include '**/*.png'
include '**/*.gif'
include '**/*.jpg'
exclude '**/*.DS_Store'
exclude '**/.gitignore'
exclude '**/.thumb'
exclude '**/build'

doFirst {
println "==================== Copying gui components into assets"
}
}


task zipGui(dependsOn: copyGui, type: Zip) {
FileTree zip = zipTree('assets/htdocs/gui.zip')
from 'assets/htdocs'

doFirst {
println "==================== Zipping GUI components"
}
}

最佳答案

在此处查看zip任务的详细信息:https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Zip.html

      task zipGui(type: Zip) {
archiveName = 'gui.zip'
from("$projectDir/../../../install") {
into 'assets/certs/root'
include 'ca.pem'
}
from("$projectDir/../../web/gui"){
into 'assets/htdocs'
exclude '**/*.DS_Store'
exclude '**/.gitignore'
exclude '**/.thumb'
exclude '**/build'
} // Just include or exclude is enough here as you indicated.
destinationDir(file("$buildDir/libs"))
}

关于gradle - 如何使用 'dependsOn'如何执行Zip类型的任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51370575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com