Is there an elegant way to use a specific dependency as a file object (cast dependency to file object).
It is often needed to pass a file as an argument to a task/ant task etc.
I helped me with
configurations.myDependency.files.iterator().next()
But this looks not very intuitive.
Is there an elegant way to use a specific dependency as a file object
Share
I think you mean configuration not dependency. Assuming you have something like:
Then, if you are confident there is going to be only one file in all of your dependencies for
myConfthen you can doconfigurations.myConf.singleFile(return type isFile).However, since configuration can contain multiple files, in order to make your code more robust you should iterate over all files in
configurations.myConf.files(return type isSet<File>).If you need to extract specific dependency jar from a configuration you can do something like:
where
depis of typeDependencyand the return type isSet<File>.For more details see Configuration javadoc.