我需要定制我的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'
}
}
所以,我需要重写(覆盖)jar
中默认的from
配置。这是否可行?
jar
任务的行为。 - RomanMitasov