Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle creates war with servlet-api 2.5 instead of 3.0.1

I'm using Gradle 1.9 (extra details below) to build a WAR that will run over Jetty 9 (jetty-9.0.5.v20130815).

It is configured in 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 -

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.jackson:jackson-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/.

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.

Is it a dependency of other library? Is this a bad thing?

like image 732
Kof Avatar asked Dec 03 '22 21:12

Kof


1 Answers

You can run dependencies report to see which library pulls in servlet-api-2.5:

gradle dependencies --configuration runtime

Once you know which library pulls in servlet-api-2.5, you have two options:

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:

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'

like image 197
kukido Avatar answered Jan 13 '23 02:01

kukido