Gloria Santin
Gloria Santin

Reputation: 2136

Cannot exclude directories for a Gradle copy task

I have a gradle script in which I want to copy 3 directories into another folder. But I also have to exclude directories. This is the tree structure I start with:

src > java > tms > common  
src > java > tms > dla 
src > java > tms > server 
src > java > tms > javaserver > common 
src > java > tms > javaserver > dock > transaction > local 
src > java > tms > javaserver > dock > transaction > tcd 
src > java > tms > javaserver > dock > transaction > files

The folders I want to copy are:

src > java > tms > common 
src > java > tms > javaserver > common
src > java > tms > transaction > local
src > java > tms > transaction > files 

This is the Gradle command I am using:

task copyTmsCoreSharedFiles(type: Copy) {   
    from ('src/java/com/fedex/ground/tms')  
    include '**/common/*'   
    include '**/javaserver/common/*'            
    include '**/javaserver/dock/transaction/*'  
    exclude '**/javaserver/dock/transaction/tcd*'       
    into  rootProject.rootDir.getAbsolutePath() +"/target-ant"+"/tmscoreshared"
}

The results are that all folders are created. All of the folders under dock are included. ( When I select only the transaction folder, why are the other folders included?) The exclude directive is not working at all.

Thanks.

Upvotes: 5

Views: 6152

Answers (1)

Opal
Opal

Reputation: 84786

This should work:

ext.dest = project.file("target-ant/tmscoreshared")

task copyTmsCoreSharedFiles(type: Copy) {
    includeEmptyDirs = false
    from ('src/java/com/fedex/ground/tms')
    exclude '**/dla/**'
    exclude '**/server/**'
    exclude '**/tcd/**'
    outputs.dir(dest)
}

task clean {
  doLast {
    dest.delete()
  }
}

You can also find a demo here.

Upvotes: 8

Related Questions