Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 493
Gloria Santin Avatar asked Mar 05 '23 06:03

Gloria Santin


1 Answers

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.

like image 90
Opal Avatar answered Mar 10 '23 10:03

Opal