Explicitly marking repo for dependencies

Gradle Team,

In my organization, I have written groovy based gradle build scripts (for past 6 years) for lot of legacy multi-project builds after lot of source splits, making modules acyclic, etc. Many a times, I have faced with a difficulty of how gradle chooses repository for downloading dependencies.

When we have only maven central, there is no problem and everything works fine. Our company has in-house maven repositories for different set of dependencies. So, for certain group, we have to go to different repos for different set of dependencies.

I m aware that include* and exclude* calls while declaring the repos and we are achieving using those now. Everything works fine. But, this approach has 2 problems

  1. This necessitates editing the common build script (because, that is where all the repositories are defined) to include groups and artifact-name of dependent projects. Editing the common build.gradle for this purpose would always disturb me.
  2. When the include* and exclude* list grows big, maintaining that becomes difficult

During those times, I have always felt that there has to be one extra facility to attach a repo whlie declaring dependencies.

Below syntax is just an illustration of the concept giving each repository a name and using that name explicitly while defining the dependency. If repo name is not explicitly given, it will follow the gradle's regular protocol to find the repo.

maven {
   url "http://local.url/path"
   name 'mavenrepo01'

dependencies {

   mavenrepo01 {
      implementation (group: 'mysql', name: 'mysql-connector-java', version: '5.1.34', classifier: 'bin')
      implementation  "wizard1:wizard1:x.x"

   implementation  "com.tinkerpop.blueprints:blueprints-core:2.6.0"
   implementation  "commons-configuration:commons-configuration:1.6"
   implementation  "com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.1"
   implementation  "com.tinkerpop.gremlin:gremlin-groovy:2.6.0"

I am referring every release notes to discover such facility but in vain (in a lighter sense).

I am aware that I am coming from a problem. Fitting gradle’s all the current features in this may have lot of challenges.

I just want to know whether attaching repo during dependency declaration has been considered and ruled-out by gradle team or is there ways that such facility may become part of future releases of gradle…

Can you please throw light in this?

As repositories actually end up being a NamedDomainObjectContainer, there’s actually nothing that prevents you from declaring them all centrally with a name, but then configuring your includes/excludes in the dependent project that actually contains the dependencies.

In fact, I think a well written method could actually make the syntax you showed work in your build (configuring the includes behind the scenes) without any changes to Gradle itself.

Thanks for the reply. Got some ideas. I will make a try.

Will it be cupidity from my side to expect this direct facility in gradle itself to have better semantics than include* and exclude* methods…?