Gradle will execute a task at most once per gradle invocation. I’m guessing you’re not doing the exact same thing twice (eg the task inputs are changed between the first and second invocation?)
It’s likely you’ll need two tasks, most likely of the same type but with different inputs/outputs.
I suggest you use separate input/output files/directories for each so that Gradle’s up to date check caching/skipping can still work.