Fwd: Dependency substitution sample

1,227 views
Skip to first unread message

Daz DeBoer

unread,
Apr 15, 2015, 8:44:03 PM4/15/15
to Gradle Development List
So there's still some more work to do, but dependency substitution is functional in master.

Here's a little sample I created for Hans to demonstrate this new functionality. By combining a dynamic settings.gradle and a substitution rule, you have a fluid multi-project build!

---------- Forwarded message ----------
From: Daz DeBoer <darrell...@gradleware.com>
Date: 15 April 2015 at 14:22
Subject: Dependency substitution sample
To: Hans Dockter <hans.d...@gradleware.com>

Hi Hans

Here's a sample that demonstrates dynamically replacing external deps with project deps, based on the existence of a matching project.

To use (assuming a recent build of gradle from master):

gradle uploadArchives
gradle dependencies --configuration compile
mv sub2 .. // Get it out of the project
gradle dependencies --configuration compile

There are 2 bits of magic:
2. build.gradle includes a dependency substitution rule that looks for a matching project for any external dependency in the group "org.example".

You'll notice that this works transitively (can replace a transitive external dependency with a project dependency). 
--
Darrell (Daz) DeBoer
Join us for Gradle Summit 2015, June 11 - 12 in Santa Clara, CA: http://www.gradlesummit.com
dependency-substitution.zip

Yohan

unread,
Jun 23, 2015, 12:09:04 AM6/23/15
to gradl...@googlegroups.com
Hi Darrell,

Ran this sample against 2.6-20150622220042+0000 and getting this error below, am I missing something?

* Where:

Build file '/Users/yhartanto/Downloads/dependency-substitution/build.gradle' line: 23


* What went wrong:

A problem occurred evaluating root project 'dependency-substitution'.

> No signature of method: org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.DefaultDependencySubstitutions.eachModule() is applicable for argument types: (build_adm3y3p13itj9u5h6fywxclvs$_run_closure1_closure5_closure9) values: [build_adm3y3p13itj9u5h6fywxclvs$_run_closure1_closure5_closure9@2db833ca]


* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Sterling Greene

unread,
Jun 23, 2015, 12:24:16 AM6/23/15
to gradl...@googlegroups.com
Hi Yohan,

The API has changed a bit since this original email, see the release notes:

--
You received this message because you are subscribed to the Google Groups "gradle-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gradle-dev+...@googlegroups.com.
To post to this group, send email to gradl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gradle-dev/35ebc2f4-a7fa-41c5-8116-b3672ef28acd%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Daz DeBoer

unread,
Jun 23, 2015, 12:24:56 AM6/23/15
to Gradle Development List
Hi Yohan
The DSL for dependency substitution has changed a bit since the sample was created. For now, you should check out the dependency-substitution sample: https://github.com/gradle/gradle/tree/master/subprojects/docs/src/samples/dependency-substitution, or the user guide chapter: https://docs.gradle.org/nightly/userguide/dependency_management.html#dependency_substitution_rules.

Daz

--
You received this message because you are subscribed to the Google Groups "gradle-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gradle-dev+...@googlegroups.com.
To post to this group, send email to gradl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gradle-dev/35ebc2f4-a7fa-41c5-8116-b3672ef28acd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Daz DeBoer
Principal Softare Engineer

Yohan

unread,
Jun 23, 2015, 11:32:57 AM6/23/15
to gradl...@googlegroups.com
Hi Darrell/Sterling,

Thank you for the help. When testing the substitution rule, I found that the notation in useTarget doesn't support ext like in the dependencies declaration, https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/groovy/org/gradle/api/artifacts/ModuleVersionSelector.java

For example below, the @aar is treated as part of the version as opposed to extension. Can I please request ext to be supported, this will help us Android folks a lot. If it is not in the roadmap, may be a pointer for me to submit a PR.

configurations.all {
   resolutionStrategy
.eachDependency { DependencyResolveDetails details ->
   
if (details.requested.name == 'fabric') {
     details
.useTarget('io.fabric.sdk.android:fabric:1.3.4@aar')
   
}
}

Daz DeBoer

unread,
Jun 24, 2015, 2:38:54 PM6/24/15
to gradl...@googlegroups.com
On Tue, Jun 23, 2015 at 9:32 AM Yohan <yohan.h...@gmail.com> wrote:

Thank you for the help. When testing the substitution rule, I found that the notation in useTarget doesn't support ext like in the dependencies declaration, https://github.com/gradle/gradle/blob/master/subprojects/core/src/main/groovy/org/gradle/api/artifacts/ModuleVersionSelector.java.  

For example below, the @aar is treated as part of the version as opposed to extension. Can I please request ext to be supported, this will help us Android folks a lot. If it is not in the roadmap, may be a pointer for me to submit a PR.

configurations.all {
   resolutionStrategy
.eachDependency { DependencyResolveDetails details ->
   
if (details.requested.name == 'fabric') {
     details
.useTarget('io.fabric.sdk.android:fabric:1.3.4@aar')
   
}
}



Strictly speaking, this is a 'dependency resolve rule', not a 'dependency substitution rule', but the restriction to only permit "group:name:version" in the target is the same in both cases, and intentional.

We don't have current plans to extend this to allow other 'dependency' attributes to be specified in the rule. However, if you omit the '@aar' part of the 'useTarget' parameter, the original dependency attributes (including artifact type) will be retained. Please try it out and see if it works for you.

Reply all
Reply to author
Forward
0 new messages