Sharing gradle configurations through module dependencies


(Ferghal Smyth) #1

Hi,

I’m using the solution describe here ( http://stackoverflow.com/questions/18738888/how-to-use-provided-scope-for-jar-file-in-gradle-build ) to add provided dependencies for compilation. The solution works fine however I have multiple projects that depend on the same configuration and to avoid redeclaring the configuration for each project I was hoping that the configuration could be inherited between dependent projects. I have a work around that moves the configuration out to a separate file and applies to each project but I would prefer if the configuration was inherited through dependencies between projects.

Is this possible?

Thanks, Ferg


(Peter Niederwieser) #2

I don’t quite understand what you are saying. If multiple projects depend on the same configuration in another project, only the latter project needs to declare that configuration. If, on the other hand, each project has provided dependencies, each will need to declare its own ‘provided’ configuration. This can be done in the ‘subprojects {}’ block of the root project, or in a script plugin that gets applied in each project’s build script.


(Ferghal Smyth) #3

I have a module A where I have defined the configuration and provided dependencies as shown in the link provided above. Modules B and C depend on A but upon compilation errors occur because it can’t resolve certain classes. I thought because it was defined in A that B and C would inherit the configuration and dependencies. Duplicating the configuration in B and C allows compilation to succeed.

As a work around similar to what you suggested I apply the separate configuration file to certain subprojects as follows.

configure(subprojects.findAll {it.name != 'moduleX'}) {
 apply from: 'gradle/provided.gradle'
}

(Peter Niederwieser) #4

This is the correct approach.