Java Gradle 使用 servlet-api 2.5 而不是 3.0.1 创建战争
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20608535/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle creates war with servlet-api 2.5 instead of 3.0.1
提问by Kof
I'm using Gradle 1.9 (extra details below) to build a WAR that will run over Jetty 9 (jetty-9.0.5.v20130815).
我正在使用 Gradle 1.9(下面有更多详细信息)来构建一个将在 Jetty 9 (jetty-9.0.5.v20130815) 上运行的 WAR。
It is configured in web.xml
-
它被配置在web.xml
-
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
...
build.gradle has this dependency -
build.gradle 有这个依赖 -
repositories {
mavenCentral()
}
dependencies {
providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
compile 'org.springframework:spring-webmvc:3.2.2.RELEASE'
compile 'javax.mail:mail:1.4.7'
compile 'org.codehaus.Hymanson:Hymanson-mapper-asl:1.9.13'
compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'commons-net:commons-net:3.3'
compile 'mysql:mysql-connector-java:5.1.26'
compile 'org.springframework:spring-jdbc:3.2.4.RELEASE'
compile 'commons-fileupload:commons-fileupload:1.3'
compile 'commons-pool:commons-pool:1.6'
compile 'commons-dbcp:commons-dbcp:1.4'
compile 'log4j:log4j:1.2.17'
compile 'org.slf4j:slf4j-api:1.7.5'
compile 'org.slf4j:slf4j-log4j12:1.7.5'
runtime 'javax.servlet:jstl:1.1.2'
}
building using gradle clean war
produces a WAR file with servlet-api-2.5.jar
in WEB-INF/lib/
.
构建 usinggradle clean war
会生成一个带有servlet-api-2.5.jar
in的 WAR 文件WEB-INF/lib/
。
More env details -
更多环境细节 -
Build time: 2013-11-19 08:20:02 UTC
Build number: none
Revision: 7970ec3503b4f5767ee1c1c69f8b4186c4763e3d
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Ivy: 2.2.0
JVM: 1.7.0_45 (Oracle Corporation 24.45-b08)
OS: Mac OS X 10.9 x86_64
The webapp seem to work without servlet-api-2.5.jar
(deleted it manually), but I haven't checked all functionality available.
webapp 似乎没有工作servlet-api-2.5.jar
(手动删除它),但我没有检查所有可用的功能。
Is it a dependency of other library? Is this a bad thing?
它是其他库的依赖项吗?这是坏事吗?
采纳答案by kukido
You can run dependencies report to see which library pulls in servlet-api-2.5:
您可以运行依赖关系报告以查看哪个库拉入 servlet-api-2.5:
gradle dependencies --configuration runtime
Once you know which library pulls in servlet-api-2.5, you have two options:
一旦你知道哪个库拉入了 servlet-api-2.5,你有两个选择:
Disable transitive dependencies for the library:
禁用库的传递依赖项:
runtime('org.hibernate:hibernate:3.0.5') {
transitive = false
}
runtime group: 'org.hibernate', name: 'hibernate', version: '3.0.5', transitive: false
Exclude a particular transitive dependency:
排除特定的传递依赖:
compile('org.hibernate:hibernate:3.1') {
//excluding a particular transitive dependency:
exclude module: 'cglib' //by artifact name
exclude group: 'org.jmock' //by group
exclude group: 'org.unwanted', module: 'iAmBuggy' //by both name and group
}
If you wonder, why this conflict was not resolved by Gradle automatically, it is because 2.5 and 3.0 have different names:
如果您想知道为什么 Gradle 没有自动解决此冲突,那是因为 2.5 和 3.0 具有不同的名称:
javax.servlet:servlet-api:2.5
javax.servlet:javax.servlet-api:3.0.1
Hope it helps.
希望能帮助到你。
Update:
更新:
I looked at 'javax.servlet:jstl:1.1.2', it depends on 'javax.servlet:jsp-api:2.0', which depends on 'javax.servlet:servlet-api:2.4'
我看着'javax.servlet:jstl:1.1.2',它取决于'javax.servlet:jsp-api:2.0',它取决于'javax.servlet:servlet-api:2.4'
回答by Steven
In more recent versions of gradle you can make use of module replacement:
在较新版本的 gradle 中,您可以使用模块替换:
dependencies {
modules {
module("javax.servlet:servlet-api") {
replacedBy("javax.servlet:javax.servlet-api")
}
}
}