What is the gradle way to filter a subset of files in src/main/webapp?

China☆狼群 提交于 2019-12-05 14:33:44

问题


I'm doing a maven conversion to gradle and want to see the opinions on the best way to perform the following. I currently have multiple files under src/main/webapp. Some need filtered one way and some need filtered in another.

Notionally under src/main/webapp I have a directory foo containing html and binaries and under webapp many other files including html. I want to filter just the foo/*.html files.

In my notional build.gradle I can either do:

war {
  eachFile {
    if(shouldFilter(it)) {
      it.filter(ReplaceTokens, tokens: [key: 'value'])
    }
  }
}

def shouldFilter(input) {
  input.path.contains('foo') && input.name.endsWith('.html')
}

or move each subset into its own directory that is not copied by default

war {
  from('src/main/foo-pre-filter') {
    into 'foo'
    include '*.html'
    filter(ReplaceTokens, tokens: [key: 'value'])
  }
}

Or is there another option I missed?


回答1:


If I understand the question correctly, you can use filesMatching. Also, I would do it as part of the processResources task, as opposed to the war task. It would look something like this:

processResources {
    filesMatching('foo/*.html') {
        filter(ReplaceTokens, tokens: [key: 'value'])
    }
}

I realize the initial question was asked 2 years ago, so this probably won't help the asker, but perhaps it could help someone else in the future.



来源:https://stackoverflow.com/questions/9608615/what-is-the-gradle-way-to-filter-a-subset-of-files-in-src-main-webapp

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