I’d like to achieve what is documented in Understanding implicit conversion to file collections
for my own DSL.
I tried to look at the mentioned JavaCompile task and came up with this solution:
class ModelBeansExtension {
final ConfigurableFileCollection modelDirs
final Project project
ModelBeansExtension(Project project) {
modelDirs = project.layout.configurableFiles()
this.project = project
}
void setModelDirs(FileCollection dirs) {
this.modelDirs.setFrom(dirs)
}
void setModelDirs(Object dir) {
this.modelDirs.setFrom(project.file(dir))
}
void setModelDirs(Object... dirs) {
this.modelDirs.setFrom(project.files(dirs))
}
}
This kind of works. I can use
modelBeans {
modelDirs = 'some-path'
}
in my build script and could also supply a file or file collection to the “modelDirs” property.
However it feels wrong to store the project in the extension object. Isn’t a “project” property now also a part of my DSL?
Is there a better way?