My (very limited) understanding is that component metadata is looked at after the dependencies are resolved, but before a particular version is selected.
The seems to indicate that I can look at all the Ivy versions I selected, but not necessarily discard / select the ones I need.
My organisational repo is setup like this (I can’t change it as this time): /repository/[organisation]/[module]/([branch]/)[revision]/artifact.[ext]
So, I’d like to use the [branch] parameter as part of the artifact path, but I can always work around that by adding multiple resolver patterns.
What I think I need to do is to add the ‘branch’ specifier to the “component”, like this:
The short answer is that you can’t do this yet. In 2.2 we will be introducing component selection rules that will allow you to programmatically control how versions are selected (i.e. one of the things you will be able to do is query the metadata and reject versions that don’t have a desired branch). If you are interested, I would encourage you to try it out with one of the nightly builds - take a look at the nightly release notes for examples on using selection rules. Note that this stuff is under very active development right now, so treat it accordingly.
Thanks for the quick response. It is very appreciated.
That’s really good news that it’s coming in version 2.2… Looking at the release notes, it looks like the selectors will be “separated” from the definition… So reusing my example from above, i’d need something like this?
configurations {
rejectConfig {
resolutionStrategy {
componentSelection {
all { ComponentSelection selection, IvyModuleDescriptor descriptor, ComponentMetadata metadata ->
if (selection.candidate.group == 'my.org' && selection.candidate.module == 'project') {
if (descriptor.branch != 'develop')
selection.reject("Not in the dev branch")
}
}
if (selection.candidate.group == 'my.org' && selection.candidate.module == 'logger') {
if (descriptor.branch != 'release')
selection.reject("Not in the release branch")
}
}
}
}
}
}
}
dependencies{
compile group:'my.org', name:'project', version:'1.0+'
compile group:'my.org', name:'logger', version:'1.0+'
}
I am happy to write a “generic” selector for this if i could associate the data with the dependency declaration, perhaps by adding a “extra” map to the ExternalModuleDependency class.
Yep, although the configuration has to match (either use rejectConfig or compile for both the rules and the dependencies). Also, to make it a little cleaner, you could use the module targeting and leave off the ComponentMetadata argument if you’re not going to use it. For instance:
configurations {
compile {
resolutionStrategy {
componentSelection {
module("my.org:project") { ComponentSelection selection, IvyModuleDescriptor descriptor ->
if (descriptor.branch != 'develop') {
selection.reject("Not in the dev branch")
}
}
module("my.org:logger") { ComponentSelection selection, IvyModuleDescriptor descriptor ->
if (descriptor.branch != 'release') {
selection.reject("Not in the release branch")
}
}
}
}
}
}
dependencies {
compile group:'my.org', name:'project', version:'1.0+'
compile group:'my.org', name:'logger', version:'1.0+'
}
If you wanted a generic selector, there’s probably a couple of ways you could do that, but yeah, you’d need to map group:name to branch (maybe in a project extension?) and then populate that mapping (maybe in the dependency configuration closure?).
Here in the artifactory repository server we need to specify the branch from where the artifact needs to be downloaded. But the in the ivy layout artifact pattern defined above I need to specify a branch without which dependency resolution doesn’t work. What should I do in that case? If i leave out the branch in the artifact pattern, it doesn’t work. if I keep the branch value(‘trunk’) then I cannot get to the branch RB-1.40 Please advise.