How to pass variable length of arguments to JavaExec?

For fixed length arguments, we could do this

args = [arg1, arg2]

However, my java program could accept variable length of arguments, it can be 5, 10, and so on.

How to define that in gradle?

I have figured out and posted my solution here.