I would like to execute inside my task (in my own plugin) a task from a other plugin. Before the cyclone task is executed i need to set some configuration settings. The problem is that the cyclone task is not executed. Any hints what wrong?
public class MyTask extends DefaultTask {
@TaskAction
public void perform() {
CycloneDxTask task = (CycloneDxTask) getProject().getTasks().getByName("cyclonedx");
task.setIncludeConfigs(List.of("runtimeClasspath"));
task.setSkipConfigs(List.of("compileClasspath", "testCompileClasspath"));
task.doLast(task1 -> {
getProject().getLogger().info("doLast: " + task1.getDescription());
});
}
}
You cannot “invoke” tasks, you can only depend on them.
And you shouldn’t configure tasks from the execution phase, even other tasks.
At least that is then incompatible with the configuration cache.
If you really want to do it, you should make the cyclonedx task depensOn your custom task that configures it, so that if the cyclonedx task is run, your task is run first and can configure it.
If you want the cyclonedx task to always run when your custom task was run you can also add additionally a finalizedBy from your task to cyclonedx.
But again, this is not compatible with configuration cache, so should better be avoided.
For that you have basically two options in your convention plugin.
Either you say “whenever my convention plugin is applied, the cyclone dx plugin also needs to be applied and configured”, then you want something like: