Exclude configuration from project

I am trying to create a plugin which can exclude specific configuration from the project and I have a few questions.

Let’s say I have a project with following configurations:


So when I want to build such project, all dependencies for all configuration will be downloaded.
And this is what I want to change.

I want to be able to exclude test configuration from given project, so test dependencies are not downloaded.

My first attempt was to try to remove test configuration from configurations container, but in this case project fails during evaluation stage.

So the ultimate goal is to make it possible to build project w/o downloading dependencies for specific configuration

Only dependencies for configurations that are used are downloaded. If you don’t run the tests then the test dependencies aren’t downloaded.

If you run the tests then you obviously need their dependencies, otherwise they wouldn’t work.

Hm… that’s not what Im seeing actually. Even if I don’t run tests, Gradle still complains that Im missing those dependencies.

But it might actually be the Android Gradle plugin problem (yes, this is an Android project)…

Indeed, the Android plugin resolves all dependencies at configuration time. The Android team is working on a fix for that. In the meantime you could use this workaround to get rid of dependencies:

configurations.testCompile.dependencies.all { dep ->
  configurations.testCompile.exclude group: dep.group, module: dep.name

This excludes all dependencies as soon as they are added to the configuration.

1 Like

Aha, thanks a lot! Do you have a bug reference by any chance, so I can subscribe to updates?

You can follow the 2.3-alpha releases, they are making plenty of great performance improvements and resolving dependencies later will be part of that.

1 Like