Cannot exclude directories for a Gradle copy task

为君一笑 提交于 2020-03-01 04:53:10

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/52768723/cannot-exclude-directories-for-a-gradle-copy-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!