I am developing a custom plugin which introduces a task for creating a zip file of things within the project which will then get uploaded into some other repository outside of gradle. By default I want to provide a default setup of things that should get included in the zip, but I also want to provide a way for this to be added to and/or overridden in a particular project.
This is what I have for my plugin:
class CustomPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.configure(project) {
buildDir = file("${project.projectDir}/target")
task(type: Zip, description: 'Builds artifacts.zip that gets exploded into a new asset', group: 'Asset Management', 'buildDistributionZip') {
archiveName = 'artifacts.zip'
from(buildDir) {
include 'distributions/**'
include 'docs/**'
include 'libs/**'
include 'reports/**'
include 'test-results/**'
}
}
}
}
}
This works great for projects that don’t define their own buildDistributionZip {} block, or for projects that want to add onto what goes into the zip. My question is, what if a project wants to completely override/remove the defaults and configure its own?
For example I can do this in a project’s build.gradle:
buildDistributionZip {
from 'src'
}
Which, in addition to the things from buildDir, would also add everything from $projectDir/src into the zip. What if I just wanted $projectDir/src in the zip file and not the things from buildDir?