javagroovybuildbuild-processgradle

Gradle: War Task has Conflicting Includes/Excludes


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.


Solution

  • 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'"
      }
    }