Can we run tasks in parallel in single build project

In the first example your issue is that the logic is running at configuration time (not parallelized) instead of execution time. You’ll need to put that logic in a task action (i.e. method annotation with @TaskAction). Be aware also that tasks with custom actions (i.e. doLast or doFirst) will never be run in parallel.

 Custom actions
 
 Any task that has custom actions (i.e. ones added via {@link org.gradle.api.Task#doLast(org.gradle.api.Action)} or {@link org.gradle.api.Task#doFirst(org.gradle.api.Action)})
 is not considered parallelizable even if its type carries this annotation.
 This is because it cannot be known whether the added action is parallel safe or not.
2 Likes