Gradle: War Task has Conflicting Includes/Excludes

江枫思渺然 提交于 2019-12-10 04:13:19

问题


I am trying to build a war file with Gradle, but I'm having an issue excluding one directory and including another that happen to have the same names, but different parent directories.

Please notice in the first code example below that neither of the css/ directories are being included in the final war file -- I assume because Gradle thinks that I want to exclude any directory named css/ regardless of its absolute path.

Basically I want to exclude src/main/webapp/css and include build/tmp/css because the latter contains the minified code. How can I achieve this? I've tried specifying an absolute path in various ways but haven't had any success.

war {
  dependsOn minify
  from('build/tmp/') { include ('css/') }
  exclude('WEB-INF/classes/', 'css/')
}

If I don't exclude css/ like so:

war {
  dependsOn minify
  from('build/tmp/') { include ('css/') }
  exclude('WEB-INF/classes/')
}

then the result is that both the minified and non-minified code is included.


回答1:


I am not sure why you exclude WEB-INF/classes/css instead of src/main/webapp/css in your build.gradle, but copying the minified CSS files instead of the original ones is achieved by:

apply plugin: 'war'

war {
  // dependsOn 'minify'

  from 'src/main/webapp'
  exclude 'css' // or: "exclude 'WEB-INF/classes/css'"

  from('build/tmp/css') {
    include '**/*.css'
    into 'css' // or: "into 'WEB-INF/classes/css'"
  }
}


来源:https://stackoverflow.com/questions/12752580/gradle-war-task-has-conflicting-includes-excludes

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