How to set identifier to ConfigurableFileCollection dependency?

I want to need build some dependencies before gradle android plugin resolve it.
I use a custom method:

subprojects {
  dependencies.ext.mavenProject = { artifactId ->
  files("${getJar(artifactId)}.jar").builtBy(rootProject.myJarTask)
  }
  dependencies {
    compile mavenProject("mygroup:myDependency:1.0")
    compile mavenProject("mygroup:myDependency:1.0")
  }
}

So, I have a two different dependencies resolved to one jar.
I need a possibility add dependency multiple times(I have a multimodule project with transitive dependencies) and have only one dependency in my ‘compile’ configuration.
Maybe I can set identifier to dependency?

The artifactId already is your identifier. Just keep a Map from artifactId to FileCollection and you’re done :slight_smile:

1 Like

ArtifactId is really identifier.
And I can write something like :

def addMavenDependency(config, id) {
  if(!dependencyMap.contains(id)) dependencies.add(config, mavenProject(id))
}

But can I use common syntax somehow? This one:

dependencies {
  compile mavenProject("mygroup:myDependency:1.0")
}

Do the caching in the mavenproject method instead of adding another method.