How to filter the artifacts of a non resolved configuration, using the name/type/group of the artifacts


(Stephane Galles) #1

I’m trying to filter the artifacts of a non resolved configuration using the name/type/group of the artifacts.

That’s to say, I’m looking for something that looks like

FileCollection#filter(Spec<? super File> filterSpec)

but that is more like

Configuration#filter(Spec<? super ArtifactIdentifier> filterSpec) // I made this up

Is there something in the API that would allow me to achieve that ?

Thank you.


(Peter Niederwieser) #2

Is ‘Configuration#fileCollection(Spec<? super Dependency>)’ what you are looking for?


(Stephane Galles) #3

AFAICT Configuration#fileCollection(Spec) is a bit too coarsed grain.

That’s to say, it seems that Configuration#fileCollection(Spec) does not allow me to filter one given artifact (for exemple using the artifact name). With this method I must a filter all the artifacts of a given dependency.

I’m really looking for the grain of FileCollection#filter but I would like to be able to use the metadata of the artifact (that is partially lost in the name of the File).

But maybe there’s a way to use Configuration#fileCollection(Spec) with this grain ?


(Peter Niederwieser) #4

When interacting with Maven repositories, ‘Configuration.fileCollection()’ should be all you need. There will be only one main artifact per dependency, and only main artifacts will be returned. If you need more information, such as all artifacts for a particular (Ivy) dependency, try the ‘Configuration.resolvedConfiguration’ API.


(Stephane Galles) #5

Yes, actually I have to filter configurations from an Ivy repository, and Configuration.resolvedConfiguration, well, resolves the configuration, so it is kind of awkward when it must be used with a copySpec (resulting in a lot of “configuration time” resolved configurations).

I think that I will stick with FileCollection#filter that does not force me to resolve the configuration (even though it forces me to tokenize the name of the file to retreive the type or the name of the artifact)

Thank you Peter.


(Peter Niederwieser) #6

You can defer execution of code in copy specs by using closures, e.g. ‘from { … }’ or ‘into { … }’.


(Stephane Galles) #7

yes ! it makes sense. I had forgotten that I could use the “deferred execution”/“resolvedConfiguration” combination. Thank you again.