How to subtract one configuration from another?


(Magnus Granander) #1

Hi,

I wonder if there is any way to subtract from a configuration in a similar way that you do extendsFrom?

What I’m trying to achieve is this:

I’m building a WAR file and I’m using the “provided” configuration from Nebulas plugin (and another configuration that is a bit of a hack) to avoid getting some dependencies in the classpath:

war { classpath = [configurations.runtime - configurations.provided - configurations.removeFromWar] ... }

I know this is not the preferred way to do things, but this is what I’ve got :slight_smile:

I would rather like to have a configuration that does the subtraction beforehand so that I can easily see changes in the dependencies. Something like:

configurations { warConfiguration warConfiguration += configurations.runtime.minus(configurations.provided).minus(configurations.removeFromWar) }

From what I read, Configurations are FileCollections, and therefor I would think that this is doable. I haven’t just figured out how.

So, is it possible?


(Lance Java) #2

I personally consider excluding / subtracting to be a hacky practice and always try to avoid it if possible. In this case you may accidentally subtract a transitive dependency that’s in two configurations. Are you sure there’s not a solution to group your dependencies into configurations and only add together what you need for a given scenario?

Also, are you aware of the compileOnly configuration added in gradle 2.12?


(Magnus Granander) #3

As I said in my previous post, this is not the preferred way of doing things :slight_smile: But as so many times you got what you got and need to handle it. Moving over to compileOnly is one of the reasons I want to see the current classpath so that I can use a plugin that compares the old classpath to the new when I change the configuration.

I’m thinking of temporary hacking together something that can output the current classpath so I can continue and remove the horrible configuration hack that I got now :slight_smile:


(Lance Java) #4

I think you’d do it like:

configurations {
   warConfiguration
}
dependencies {
   warConfiguration configurations.runtime.minus(configurations.provided).minus(configurations.removeFromWar)
}
war {
   classpath = configurations.warConfiguration
}