I’m working on a custom plugin which has a task. This task is basically an exec task but with some preconfigured values to make things easier. Since it’s essentially an Exec task I’d like to be able to extend the Exec class and just take into account whatever custom configuration I have from my plugins Convention object. However I’m running into some issues because I can’t override the exec method (which is also the TaskAction) since it’s package private. I was hoping to simply override it and do some custom stuff in the overridden method and then just call the super.exec(). Since this isn’t possible, I tried another approach which was to just set the Exec tasks commandLine and arg properties in the constructor of my task. The problem with this is that the convention object hasn’t been populated at this point. Below is roughly what I have.
Plugin class:
class FooPlugin implements Plugin<Project> {
void apply(Project project) {
def javaConvention = project.convention.plugins.java
def classpath = (javaConvention == null) ? null : javaConvention.sourceSets.main.runtimeClasspath
project.convention.plugins.foo = new FooPluginConvention(classpath)
project.task('fooStart', type: FooStartTask)
}
}
class FooPluginConvention {
FileCollection classpath
FooPluginConvention(String classpath) {
this.classpath = classpath
}
}
Task class:
class FooStartTask extends Exec {
FooStartTask() {
def settings = project.convention.plugins.foo
executable
= "/bin/foo"
args settings.classpath
}
}
So, the problem here is that “classpath” on the FooPluginConvention object hasn’t been initialized yet. How would I go about doing this?