Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 944
Dave L. Avatar asked Oct 05 '12 19:10

Dave L.


People also ask

What is exclude group in Gradle?

Within the closure we call exclude , passing: group the group of the artifact we want to exclude. module the name of the artifact we want to exclude. This is equivalent to the name used to declare a dependency in Gradle.

How does Gradle resolve transitive dependencies?

Transitive dependencyBy default, Gradle resolves transitive dependencies automatically. The version selection for transitive dependencies can be influenced by declaring dependency constraints.

How do I cache Gradle dependencies?

The Gradle dependency cache consists of two storage types located under GRADLE_USER_HOME/caches : A file-based store of downloaded artifacts, including binaries like jars as well as raw downloaded meta-data like POM files and Ivy files.


1 Answers

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'"
  }
}
like image 115
Andre Steingress Avatar answered Sep 25 '22 09:09

Andre Steingress