In Ivy I can have dependency declared like this:
<dependency org="org" name="module_name" rev="12" conf="conf_name->*">
<include name="foo(.*)-bar" ext="zip" matcher="exactOrRegexp"/>
</dependency>
which will download all matching files.
How can I define similar (regex-based) dependency in Gradle?
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:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With