java - Set onlyIf dependency on Gradle plugin task -
i've implemented gradle plugin in java. followed this tutorial.
my plugin class looks follows:
public class demoplugin implements plugin<project> { @override public void apply(project project) { project.getextensions().create("demosetting", demopluginextension.class); project.gettasks().create("demo", demotask.class); } }
currently intended implement onlyif feature unfortunately did not succeed yet.
my try following:
public class demoplugin implements plugin<project> { @override public void apply(project project) { demopluginextension ext = project.getextensions().create("demosetting", demopluginextension.class); closure closure = new closure(this) { public object docall() { return ext.isexecutetask(); } }; project.gettasks().create("demoproperties", demotask.class).onlyif(closure); } }
the error observing following:
what went wrong: execution failed task ':demo'. cannot call task.setonlyif(closure) on task ':demo' after task has started execution.
i appreciate if give me hint solving issue.
finally solved using following code:
public class demoplugin implements plugin<project> { @override public void apply(project project) { demopluginextension ext = project.getextensions().create("demosetting", demopluginextension.class); project.gettasks().create("demoproperties", demotask.class).onlyif(new closure(this) { public object call(object arguments) { return true; } }); } }
please note implementation of method
public object call(object arguments)
instead of
public object docall()
Comments
Post a Comment