Add custom dependency


I have a use case where I would like to specify dependencies that have an additional property. Technically, this property is just a set of strings. I’m imagining to specify it like so:

dependencies { myDepCfg( group: 'org...', name: 'myName', version: '1.0.0', modules: ['foo', 'blah']) }

The modules property should be readable by tasks (or wherever in a script) to get the set of strings for further processing. If you now think that looks like a dependency specification, yes, modules is a simple form of what I would call an inlined, externally resolved dependency specification - they are resolved outside of Gradle (i.e., not as part of a dependency resolve mechanism at build-time by Gradle). Also, note that I just need an identifying string in this case, no separate version, group, or the like; and it’s also not required to specify transitive dependencies.

Is that possible? If so, what would be the steps (roughly) to achieve that? I have seen the classes Dependency and ModuleDependency, and I have already started to create a new interface that extends the two, but I can’t find out how to build it up altogether.

Any help appreciated.

Just in case someone has a similar problem: I could not find a direct way to implement my use case and ended up with a simple solution though it feels somewhat hacked up:

ext {
   myModules = [
      [group: 'g', name: 'n', version: '1', deps: ['a', 'b']]
   // Since `myModule` is an extension property, we can access it all around
   // the build script. In particular, the `deps` property is used by another
   // task to generate some files. 
dependencies {
   myModules.each { m ->
      myConfig "${}:${}:${m.version}"