2.14 - Unexpected servlet-api classes on plugin test classpath

I’m experiencing classpath issues using Gradle 2.14. After explicitly specifying the servlet-api I would like to use in a plugin project:

testCompile "javax.servlet:javax.servlet-api:3.1.0"

the class that is resolved in the spock spec comes from the gradle-api jar:

Class clazz = Class.forName("javax.servlet.http.HttpServletRequest")
URL source = clazz.classLoader.getResource("javax/servlet/http/HttpServletRequest.class")

I’m not sure if this is by-design or not, but it’s making it exceptionally difficult to get WireMock 2.x running in tests.

Gradle Version: 2.14
Operating System: Linux 4.4.6
Is this a regression? No

Some additional details:

Looking through the contents of

~/.gradle/caches/2.14/generated-gradle-jars/gradle-api-2.14.jar

there are a number of different libraries embedded in there:

aQute
com/amazonaws/regions
com/amazonaws/services
fr/jayasoft/ivy
javax/servlet/jsp
javax/servlet/resources
jcifs/http/ne.css
jcifs/util/mime.map
net/rubygrapefruit/platform
org/apache/ivy
org/apache/maven
org/apache/tools
org/apache/xml
org/eclipse/jdt
org/joda/time
org/mortbay/jetty
org/mortbay/xml

Q, Does this mean that gradle plugins are limited to use only the versions of these supplied libraries?

Hi Gus,

I think the problem comes from our default excludes: https://github.com/gradle/gradle/blob/a996434cbf0c7337e8c1d267bc5b5de440286284/subprojects/dependency-management/src/main/java/org/gradle/api/internal/runtimeshaded/PackageListGenerator.java#L52-L52

We’re excluding all classes starting from javax from shading. In this case, the jetty plugin comes with servlet-api bundled into its jar, and we should have excluded them. I’ll create an issue for this.

Hey Cedric,

Yup, that looks like the culprit alright. Thanks for taking a look. If you can ping me on the issue I’ll test the fix.

Cheers,

Gus.

Hi Gus,

this issue should be fixed in the latest Gradle nightly. Could you please check it out if it fixes your problem?

Cheers,
Stefan

Hi Stefan,

Yes excellent works with the latest snapshot:

distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-3.2-20160831000029+0000-bin.zip

Thanks for sorting this out, much appreciated!

Gus.