filesMatching in a CopySpec does not work at some place

I find that filesMatching under war task works but does not work when in webInf as shown in the following code:

war {
 from ('src/test/webapp') {
  filesMatching('WEB-INF/web.xml') { // filesMatching work
   expand([
    'cxf': cxf
   ])
  }
 }
 webInf {
  from ('src/test/resources') {
   filesMatching('hibernate.cfg.xml') { // filesMatching does not work
    expand([
     'hibernate': hibernate
    ])
   }
  }
  into 'classes'
 }
}

Hi Rice,

Would you be able to provide a sample app that I could use to debug this?

Take the sample webApplication/customized from gradle-1.10 samples. Change the empty file src/additionalWebInf/additional.xml to have ${variable1} in it and also change the build.gradle webInf method like below:

webInf { // adds a file-set to the WEB-INF dir.

from(‘src/additionalWebInf’) {

filesMatching(‘additional.xml’) {

expand([

‘variable1’: ‘value1’

])

}

}

}

Run gradle war. You can find that ${variable} is not replaced with value1 in the built war.

I can reproduce.

A workaround for the time being is to do:

filesMatching(’**/additional.xml’)

The issue is that the destination path is used, so the effective path is actually ‘WEB-INF/additional.xml’. I’ve raised this internally for discussion as to whether this is the right behaviour.

Raised GRADLE-3022.

Original version of above reply was wrong. Has been corrected.