Deploy JAR with custom structure: include only dir + it's contents

I have this gradle task which mostly does what I want.

  • all files in srcDir are copied, but not srcDir itself
  • all files in propDir are copied, including propDir itself

Except, all files in propBaseDir are also copied, which I don’t want.

I know I can use ‘exclude’ to exclude files, but is there a way to copy ONLY propDir and it’s files into the archive?

task deployAsJar(type: Jar) {
    from {
        files(srcDir) {
            include "**/*"
        }
    }
    from {
        files(propBaseDir) {
            include "$propDir/**"
        }
    }
    archiveFileName = "examples.jar"
    destinationDirectory = file("~")
}

Got an answer on stackoverflow.
The trick is to use ‘include * into’ :

project.ext.srcDirName = 'src'
project.ext.propDirName = 'props'

project.ext.srcDir = "${projectDir}/${srcDirName}"
project.ext.propBaseDir = "${projectDir}/base"
project.ext.propDir = "${propBaseDir}/${propDirName}"

task deployAsJar(type: Jar) {
    from (srcDir) {
        include "**/*" into srcDirName
    }
    from (propDir) {
        include "**/*" into "${srcDirName}/${propDirName}"
    }

    archiveFileName = "examples.jar"
    destinationDirectory = file(".")
}