[英]Gradle -> How to omit some jars from WEB-INF/lib
我有一个带有战争规范的子项目,如下所示:
war {
from('resources') {
include '*.properties'
into 'WEB-INF/classes/'
}
webXml = file('src/main/webapp/WEB-INF/web.xml')
}
效果很好。 创建可部署到Tomcat的单个胖战文件。 问题是,当部署到TomEE和JBoss时,我遇到了冲突(即使用Javax Servlet,Jersey等)。 所以我想排除一组罐子的战争。 我查看了Gradle war文档,看起来我需要使用排除。 我尝试了两种不同的方式,并没有将战争中的罐子排除在外:
war {
// copy properties file in classes so that
// they may be loaded from classpath
from('resources') {
include '*.properties'
into 'WEB-INF/classes/'
}
// specify web xml
webXml = file('src/main/webapp/WEB-INF/web.xml')
// remove jars that conflict with TomEE
exclude '**/javax.inject-1.jar'
exclude '**/javax.servlet-2.5.0.v201103041518.jar'
exclude '**/servlet-api-2.5.jar'
exclude '**/validation-api-1.0.0.GA.jar'
}
这是在github上托管的NetFlix / karyon项目中的子项目(karyon-examples)中。 子项目中的依赖项如下所示:
dependencies {
compile 'org.slf4j:slf4j-api:1.7.0'
runtime 'org.slf4j:slf4j-simple:1.7.0'
compile project(':karyon-extensions')
compile project(':karyon-admin-web')
}
我希望避免编辑诸如编译与运行时依赖之类的内容,尤其是在其他文件和子项目中。 事实上,我试图在上面排除的罐子在使用码头和常规tomcat运行时是良性的。
我只想在不使构建脚本复杂化的情况下排除这些jar。 我错过了什么?
谢谢
显而易见的方法是将您不希望在战争中使用的依赖项从compile
配置移动到providedCompile
,从runtime
到providedRuntime
。 应用war插件时,提供的配置将添加到您的构建中。
关于上面代码段的另一个注意事项:我认为排除不起作用,因为您在exclude语句中引用了目标路径,而应该只通过/servlet-api-2.5.jar
引用它。
你可以这样
dependencies {
compile fileTree(dir: 'WebContent/WEB-INF/lib', include: ['*.jar'])
compile("org.apache.tomcat:tomcat-jni:8.0.37")
providedRuntime("org.apache.tomcat:tomcat-jni:8.0.37")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.