After some more trial-and-error, I was able to extend Gradle to resolve dependencies with following syntax:
dependencies {
compile "org:module_name:12" {
artifact {
name "foo.*-bar"
type "zip"
}
}
}
For this, one will need project evaluation listener, that will post-process the dependencies. Resolve ivy descriptor for each dependency, parse it, match the artifact names, update the dependency's artifacts descriptors (remove the one with pattern in name and insert matched artifacts with names).
Pros:
- Properly uses Gradle's artifacts cache.
- Avoids transfer of exra (not matched) artifacts.
- Dependencies resolution mechanics is applied.
Pitfalls found during implementation:
Copy a configuration before resolving ivy descriptors. Resolved configuration (with dependencies) is considered immutable and wont be resolved again, so matched artifacts will not be downloaded
Matching different entities. After an Ivy descriptor is "resolved" and downloaded, it is somewhat tricky to match it with unresolved dependency (to update artifact descriptors), as resolved entity has different type. So far, matching on "group-artifact-version" coordinates works, but it is fragile solution.
A sample code for dependency processor can be found on GitHub (disclamer: provided "as is", no gurantees and responsibilities. But if it blows your project's working copy, please let me know)
<include name="kotlin-compiler-(.*)" ext="zip" matcher="exactOrRegexp"/>
– Hulking