Specify a classifier-like property to project dependency as opposed to external dependency


(Daniel Lacasse) #1

I would like to know if it’s possible to specify a classifier equivalent property to a project dependency. For example suppose we have the following pseudo gradle scripts:

ProjectA/build.gradle: dependencies {

compile group: ‘foo’, name: ‘ProjectC’, version: ‘1.0’, classifier: ‘value1’ }

ProjectB/build.gradle: dependencies {

compile group: ‘foo’, name: ‘ProjectC’, version: ‘1.0’, classifier: ‘value2’ }

ProjectD/build.gradle dependencies {

compile group: ‘foo’, name: ‘ProjectA’, version ‘1.0’

compile group: ‘foo’, name: ‘ProjectB’, version ‘1.0’ }

Now suppose that when project A and B are compiled, they don’t need project C anymore so when project D depend on project A and B it doesn’t need to fetch project C. Here, we use external dependencies but if we have all those project inside a multi-build environment, the dependencies would be done with project(’:ProjectX’). Everything works find except when you specify the dependency for project C where the classifier affect the compilation of project C ( since C will produce 2 artifacts, one with classifier ‘value1’ and the other with ‘value2’).

My first question is how could you specify a classifier-like property in dependency like project(’:ProjectX’)?

The best solution that I could get too was using https://github.com/pniederw/elastic-deps and hack the elastic function from the high level build.gradle to set a value to the project like project(projectName).classifier = classifierValue (classifierValue is an additional parameter to the elastic function which can take in this case ‘value1’ or ‘value2’ for project A and B respectively. This solution introduce a problem which cause that in a multi-build, the classifier can only be either ‘value1’ or ‘value2’ since the same project C instance is used for both project A and B in the dependencies. The last evaluation (of project A and B) will most likely set the classifier property to it’s corresponding value and loose the original meaning of the external dependency.

The second question is how to make sure that the classifier-like property that we set in a multi-build setup can be different depending on the project? In our example, how can we make sure that the return artifact from the dependency on project C in project A was actually compile with knowledge that the classifier need to be ‘value1’ and that in project B the dependency on C was compile with knowledge that the classifier needs to be ‘value2’.

Hope this is clear enough, if any more clarification is needed, I will try to make more clear.


(Peter Niederwieser) #2

A project can make multiple configurations available, and other projects can then choose which configuration to depend on. For an example, see “Example 50.26. Fine grained control over dependencies” in the Gradle User Guide, or ‘samples/java/multiProject’ in the full Gradle distribution.