Hi,

I’ve been testing ComponentSelection with 2.2-20140831220010+0000, and it
mostly works, except I don’t get all the candidates that I’d expect to get.

I'd like to be able to select a version of a dependency that was built from
a specific branch. Following a suggestion from Adam, by using the new
ivy-publish plugin, I put some informationin the ivy.xml about the current
branch, and the list of other branches that were available during build:

  <info organisation="com.prezi.test.target" module="boxfish-test-target"
branch="master" revision="1.0-3-g1761154" status="integration" publication=
"20140901194902">
    <ns:branches xmlns:ns="http://prezi.com/gradle/boxfish";
>master,test-branch</ns:branches>
  </info>

I set up a test project, and published a few versions of it from two
different branches, trying to simulate how things would work in real life.
Here are the versions in the order they were published:

   - 1.0-8-gf0590b3 from test-branch
   - 1.0-3-g1761154 from master
   - 1.0-9-g14ae9b9 from test-branch
   - 1.0-4-g4b991e5 from master
   - 1.0-10-g5ee4b9a from test-branch

I created another project that depends on version "1.+" of my test project.
To can track which versions are tried as candidates, I added this to the
build:

configuration.getResolutionStrategy().getComponentSelection().all(new
RuleAction<ComponentSelection>() {
@Override
public List<Class<?>> getInputTypes() {
return Arrays.<Class<?>> asList(IvyModuleDescriptor.class);
}

@Override
public void execute(ComponentSelection subject, List<?> inputs) {
IvyModuleDescriptor ivyDescriptor = (IvyModuleDescriptor) inputs.get(0);
* logger.info <http://logger.info>("Branch is {}",
ivyDescriptor.getBranch());*
for (Map.Entry<QName, String> entry :
ivyDescriptor.getExtraInfo().asMap().entrySet()) {
* logger.info <http://logger.info>("{} = {}", entry.getKey(),
entry.getValue());*
}
* subject.reject("Because we can");*
}
});

After running `gradle build` I expected to see all of the versions of my
test project printed, but I only got a few of them:

Cached resource is up-to-date (lastModified: Mon Sep 01 19:54:25 CEST
2014). [HTTP:
https://artifactory.prezi.com/prezi-client/com/prezi/test/target/boxfish-test-target/1.0-10-g5ee4b9a/ivy-1.0-10-g5ee4b9a.xml
]

Resource missing. [HTTP GET:
https://artifactory.prezi.com/external-libs/com/prezi/test/target/boxfish-test-target/maven-metadata.xml
]

Selected primary task 'build' from project :

Branch is test-branch

{http://prezi.com/gradle/boxfish}branches = master,test-branch

Selection of 'com.prezi.test.target:boxfish-test-target:1.0-10-g5ee4b9a'
rejected by component selection rule: Because we can

Branch is test-branch

{http://prezi.com/gradle/boxfish}branches = master,test-branch

Selection of 'com.prezi.test.target:boxfish-test-target:1.0-9-g14ae9b9'
rejected by component selection rule: Because we can

Branch is test-branch

{http://prezi.com/gradle/boxfish}branches = master,test-branch

Selection of 'com.prezi.test.target:boxfish-test-target:1.0-8-gf0590b3'
rejected by component selection rule: Because we can


FAILURE: Build failed with an exception.


* What went wrong:

Could not resolve all dependencies for configuration ':modules'.

> Could not resolve com.prezi.test.target:boxfish-test-target:1.+.

  Required by:

      com.prezi.test.source:boxfish-test-source:0.0-SNAPSHOT

   > This module has not been resolved.



After this I published 1.0-13-g3b3374a from master, and now only that
single version is tried as candidate:

Download
https://artifactory.prezi.com/prezi-client/com/prezi/test/target/boxfish-test-target/1.0-13-g3b3374a/ivy-1.0-13-g3b3374a.xml

Resource missing. [HTTP GET:
https://artifactory.prezi.com/external-libs/com/prezi/test/target/boxfish-test-target/maven-metadata.xml
]

Selected primary task 'build' from project :

Branch is master

{http://prezi.com/gradle/boxfish}branches = master,test-branch

Selection of 'com.prezi.test.target:boxfish-test-target:1.0-13-g3b3374a'
rejected by component selection rule: Because we can


FAILURE: Build failed with an exception.


* What went wrong:

Could not resolve all dependencies for configuration ':modules'.

> Could not resolve com.prezi.test.target:boxfish-test-target:1.+.

  Required by:

      com.prezi.test.source:boxfish-test-source:0.0-SNAPSHOT

   > This module has not been resolved.



How does Gradle decide which versions to offer as candidates for a certain
dependency?

-- 

*Pinter Lorant*
Developer at Prezi <http://prezi.com>

Reply via email to