How to build jar with several directories

I am evaluating Gradle on a small project, I need to create an archive containing a number of files and directories from the project (could be jar or zip), as the project cannot be included in the corporate subversion repository.
The required content would be (for now) the ‘src’ and ‘.hg’ directories, as well as the ‘build.gradle’ file. Leaving the single file for later, this:

task sourceDist(type: Jar) {
archiveName = "project-src.jar"
from([fileTree(‘src’), fileTree(’.hg’)])
}

will include the contents of both directories but not the parent directory themselves, so that the contents of both are all mixed up. Specifying “from” a second time will only include the second directory; “into” works but only for a single directory; I tried using the “zip” task instead of “jar” but then no archive is created (and no error message). Any suggestions?

Would you like to archive directory as follows?

  • src -> zipFileRoot/src
  • .hg -> zipFileRoot/.hg

If so, the script will be like as follows…

task sourceDist(type: Jar) {
  from('src') {
    into 'src'
  }
  from('.hg') {
    into '.hg'
  }
  baseName = 'project-src'
}

Thank you, this works beautifully! If I add

from("build.gradle")

I also get the single file.