Execute a custom task from the same module where it is created

I have created a plugin and a custom task in Module-A.
So far, to execute this custom task, I would create a different module Module-B and apply the plugin there.
In Module-B, I would be able to execute the custom task of Module-A.

Is it possible to execute the task in Module-A itself and avoid having a Module-B?

You mean in the build of module A? How should that work? That’s a hen-and-egg situation. To build the plugin / task you need to apply the plugin / task, but to apply it, you first need to build it. You can apply an older published version.