Dynamic Dependency searching

Hello,
This might seem like an odd question, but sometimes our world puts us in odd situations. I have ideas on how to code something for this but I was wondering is there a recommended way to do something like:

if projectX exists
depend on projectX
else
depend on projectX.jar from Artifactory

Here is some background but not sure it will be very clear without understanding our proprietary application.

For the application that I help manage, we have a combination of 7 different SVN repositories containing Liferay services and some dependency on each other. It’s not feasible at this time to merge the repositories or build them on one workspace. The build and deployment for an asynchronous Liferay Service Builder is anything but ordinary. We have the Gradle build working fairly well and have created a class to properly run the Async Liferay Service builder.

However, the class that builds the LR wrappers requires one of our projects that lives in the base repository. What we have done is added a dependency on project(“:shared:aon-async-service-buider”)

That works great when we are running Gradle in our base repository where that aon-async-service-buider exists.
However when I am running the build for our client repository the build will fail as aon-async-service-buider does not exist as a project in there. So ultimately we’d use Artifactory and pull that aon-async-service-buider from there.

I was hoping there was a clever way to setup a dependency search in Gradle without custom coding. I wanted to avoid maintaining two sets of the same class and also wanted to avoid coding a klugey work around.

Any thoughts?

See the stack overflow answer here which mentions dependency substitution rules and prezi pride