I have a gradle plugin, which adds an extension container.
I need to add a task based on a boolean flag on the extension container.
The issue is that the flag is always false, even if I set it to true. I guess that’s because the plugin tries to create the task before the extension properties have been read.
How can I execute some code after the extension properties have been read. Is afterEvaluate the only way?
//the plugin class MyPlugin implements Plugin {
@Override
void apply(Project project) {
project.extensions.create(‘my’, MyPluginExtension, project)
if (project.my.shouldCreateTask){
createMyTask();
//at this point,shouldCreateTask is always false
}
} }
//the extension container public static class MyPluginExtension {
final Project project
MyPluginExtension(final Project project) {
this.project = project
}
def boolean shouldCreateTask = false; }
//the project
apply plugin ‘java’ apply plugin ‘my’
my {
shouldCreateTask=true }