How to solve version conflicts of dependencies of a plugin?

How do I get the following (simplified) example dependencies to work?

dependencies {
	compile gradleApi()
	compile localGroovy()
	// some more stuff
	testCompile group: 'com.sparkjava', name: 'spark-core', version: '2.3'

The problem is that gradleAPI() pulls servlet-api-2.5-20081211.jar whereas Spark depends on javax.servlet:javax.servlet-api:3.1.0.

The test that uses Spark fails because of some missing methods in the servlet API.

How can I resolve that?

The answer is there’s not a good way to avoid it right now. See some workarounds here: Unable to use commons-io 2.4 because Gradle forces the loading of commons-io 1.4

Thanks! I’ll give that a try.

I have been working on that for some time now but just can’t get it to work. I created a minimal sample to simplify talking about it.

This seems to work, but really doesn’t (because IDEA still sees servlet-api-2.5 in the module classpath but gradlew test passes for reasons that are not clear to me)

This one does not work:

I just can’t figure out why the second example behaves different from the first one. The output from build.gradle seems to be correct (does not show servlet-api-2.5) but running it shows something different. Classes still seem to be loaded from from the old version 2.5 (see output of the corresponding unit test).

I’m at a loss here, especially as I haven’t found any way to debug Gradle build scripts from IDEA. This is a serious problem for me as gradleApi() exports a huge amount of JAR files to the class path.

Any help is very much appreciated!