How to Exclude directory and its contents in gradle war

て烟熏妆下的殇ゞ 提交于 2019-12-19 11:38:11

问题


I am using gradle war plugin, I am trying to exclude some directories inside WEB-INF directory while packing a war, but the excludes don't seem to work. This is what I have

 war {
   webInf {
        from 'src/main/config'
    }
   exclude('metadata/**')
  }

Any solution on this ?


回答1:


To exclude a folder named metadata contained in WEB-INF use the following code in your build.gradle file:

war.rootSpec.exclude("**/WEB-INF/metadata/")

or depending on your coding style you could also use:

war 
{ 
    rootSpec.exclude("**/WEB-INF/metadata/") 
}

This link on the gradle discussion forum may also be of help




回答2:


Are you looking for something like this http://gradle.1045684.n5.nabble.com/Exclude-properties-file-from-war-td3365147.html? If so only remember, that in recent versions of Gradle (I'm using 1.6) there's sourceSets.main.output. It'd helpful if you could specify what metadata is and attach your project's layout.

One more thing: you may also like to:

//remove jars only for provided compile
classpath -= configurations.providedCompile



回答3:


see this post and comments

war {
// remove classes from the classpath <<<<<<<
classpath = configurations.runtime

// add them in explicitly, with the filtering applied
webInf {
    into('classes') {
        from sourceSets.main.classes
        exclude 'org/gradle/sample/excludeme/**'
    }
}
}


来源:https://stackoverflow.com/questions/16584402/how-to-exclude-directory-and-its-contents-in-gradle-war

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