I’m making good progress with this, simply using a flatDir repo with multiple dirs for now just to try to flesh out other issues. I’ve hit one snag which I can’t figure out.
I have a number of places in the build, where I do something like this:
mod/a/b/c/build.gradle
configurations { aSpecialJar }
task buildSomeJar(type: Jar) {…}
artifacts {
aSpecialJar buildSomeJar
}
Then, in another module I make a reference to this configuration:
mod/d/e/f/build.gradle
configurations { mySpecialRefConfig }
dependencies {
mySpecialRefConfig project(path: ‘
b:c’, configuration: aSpecialJar)
}
Now, most of the time, when I have a dependency on project(‘
b:c’) is simply to the default configuration and not specified, as in compile(project(‘
b:c’)) as is typical. For dependencies like this, my DependencySubsitution rules work. However, for the case where the dependencies are of the mySpecialRefConfig project(path: ‘
b:c’, configuration: aSpecialJar) form, they fail with a message like:
Could not resolve all dependencies for configuration ‘:mySpecialRefConfg’.
Module version :mod:unspecified, configuration ‘mySpecialRefConfg’ declares a dependency on configuration ‘aSpecialJar’ which is not declared in the module descriptor for group-ignored:symName:1.0
My dependencySubsitution code in mod/build.gradle looks like this:
configurations.all {
resolutionStrategy {
dependencySubstitution {
all { DependencySubstitution dependency ->
if (dependency.requested instanceof ProjectComponentSelector) {
def symName = project(dependency.requested.getProjectPath()).symbolicName
/*
If we're running with -a, then substitute the pre-built jar, if one exists, for the
requested dependency. Otherwise, don't do a substitution
*/
if (!project.gradle.startParameter.isBuildProjectDependencies()) { // i.e. "gradle -a"
dependency.useTarget(module("group-ignored:${symName}:1.0")) // ignores group-ignored and version 1.0
}
}
}
}
}
}
The only thing I’ve been able to figure out so far is to not do the dependency substitution rule for modules which are referenced this way, but this is not a good solution at all for a number of reasons, the main one being that it will defeat the potential performance gains of substituting a pre-built jar for those modules that have lots of references.
How can I either (a) construct the substitution rules to account for this, or (2) override the rules when an alternative configuration is specified on the dependency?
Thanks