There are many syntaxes that work, with subtle differences that aren’t explained very well. A bit like perl in that way. Oh well, it’s doing what I want.
Hopefully I can explain some of the behaviour you’re seeing. I think the first example (the one that doesn’t work) ultimately fails because of this line:
include { "tar1.tar" }
That’s because the curly braces represent a closure, which is an argument of the include() method. You can find that variant documented in the DSL guide. The closure represents a function that returns a boolean value to indicate whether a matching file should be included in the tar file or not.
I’ve very rarely seen it used in build files, but you could your example to work with:
include { file -> file.name == "tar1.tar" }
Most people just use the include(String includePattern, ...) syntax, which is what you ended up going with in your working example.
Note that for archive tasks, such as Zip and Tar, there is an implicit into() representing the archive file itself. You only need to add explicit into() calls if you want to copy files into a fixed sub-directory of the archive.
Finally, your build is quite fragile because you specify the location of the tar1.tar file twice, which means if you decide to change its name, you have to remember to update it in two locations. Off the top of my head, you should be able to do this:
Note how the from() references a task. I haven’t tried it, but it should work because the Tar task has a known output file: the created tar file. Gradle works this out and makes it the input of the from(). Now if you change the location or name of the first tar file, the second task will continue to work without any modifications.