Execute tasks within a task

That your println is executed is, because you do it at configuration phase, not execution phase.
To do it in execution phase, do it in a doLast { ... } block.

Setting enabled to false like you do is bad though.
You properly use tasks.register to leverage task configuration avoidance.
But then you use tasks.getByName which immediately realizes the task and configures it which also is the reason your println is executed.
If you want to set enabled to false, do it within the tasks.register closure.
But actually there is not much need to set enabled to false, as your task does not do any action anyway, I would just leave it out.

Regarding code block, using three backticks and after them the language is exactly right.
It seems Discourse does not support line numbers in code blocks out of the box: Is it possible to show line numbers in code block? - support - Discourse Meta