[英]Gradle: jar task - override from
我需要自定义我的jar
任务,以便:
我已经制作了自定义 jar 任务,它执行我想要的操作:
task customJar(type: Jar) {
dependsOn classes
group = 'build'
// everything except resources process as usual
from sourceSets.main.output - sourceSets.main.output.resourcesDir
// and process resources to custom place
from(sourceSets.main.output.resourcesDir) {
include 'docs/**'
include 'messages*.properties'
into 'custom-folder'
}
}
但是我还是需要把内置的jar换成新的。
用create
替换它
tasks.create(name: "jar", type: Jar, overwrite: true) {
// ... custom jar spec
}
...产量
Replacing an existing task that may have already been used by other plugins is not supported
jar
任务的简单配置不起作用,因为它已经在 JavaPlugin 中配置:
jar {
// jar is already configured
// with `from sourceSets.main.output`
// so it will include everything
// AND create a custom folder
// does nothing
from sourceSets.main.output - sourceSets.main.output.resourcesDir
// adds processed resources into 'custom-folder'
// in addition to all resources processed by default behaviour
from(sourceSets.main.output.resourcesDir) {
include 'docs/**'
include 'messages*.properties'
into 'custom-folder'
}
}
所以,我需要的是from
jar
的配置重写(覆盖)默认值。 是否可以?
你几乎在那里..
tasks.create(name: "myJar", type: Jar) {
// ... custom jar spec
}
jar.enabled = false //if you want to disable the default
build.dependsOn myJar //ensure this always runs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.