How to retrieve extra properties from ivy file?


(Baiyan Huang) #1

Hi, All,

In our organization, we have extra properties in ivy file, which will be read and applied during dependency resolution, use the ivy FileSystemResolver:

<ivy-module version="2.0" xmlns:extra="http://ant.apache.org/ivy/extra">
   <info organisation="myorg" module="mymodule" revision="1.0"
        extra:jniPath="//filesystem/mylibs" />

But hence FileSystemResolver will be removed since gradle 2.0, what would be the alternative to achieve this: read the extra properties and apply it during dependency resolution.

Thanks very much!


#2

How do you use the extra attribute value in Gradle?

How is it ‘read and applied during dependency resolution’?

I’m not familiar with how this would work.


(Baiyan Huang) #3

We override a function from FileSystemResolver:

public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)

Which provide us with the information to access extra properties, there are actually a jira issue opened here: http://issues.gradle.org/i#browse/GRADLE-940


#4

OK but does your build file have access to the extra property values? The Gradle API doesn’t give you access to this information in your build, so I’m wondering how you use it.

Can you be a bit more specific about your actual use case for extra attributes?


(Baiyan Huang) #5

We cuold access the extra property values. By overriding getDependency, we could get DependencyDescriptor, from which would could get DefaultModuleDescriptor, which has an method: getExtraAttribute(http://grepcode.com/file/repository.springsource.com/org.apache.ant/com.springsource.org.apache.ivy/2.1.0/org/apache/ivy/core/module/descriptor/DefaultModuleDescriptor.java#DefaultModuleDescriptor.getExtraAttribute(java.lang.String))


(Baiyan Huang) #6

We get this extra jniPath value to populate java.library.path so our test cases and programs could run properly to loading this jni libraries.


(Baiyan Huang) #7

Hi, Deboer - do you need more information? we currently does using FileSystemResolver to get the extra information and do something with it.


#8

Nope, I think I understand how you’re currently using Ivy extra attributes. They aren’t being used in dependency resolution, but recorded by the FileResolver and used elsewhere.

There’s a (not particularly nice) solution that doesn’t use require the use of (deprecated) FileResolver: download the ivy.xml file from the repository and parse it to extract the extra attribute data you require. You can download the ivy.xml file for a module with:

configurations {

ivyModules } dependencies {

ivyModules(‘org.gradle.sample:quickstart:1.0’) {

artifact {

name = “ivy”

extension = “xml”

type = “xml”

}

} }

While it’s unlikely that Ivy extra attributes will be supported directly in the Gradle model, it’s possible that a new hook will be added that will allow you to access the raw metadata file during resolution. I can imagine this being useful for extracting custom information from pom files, ivy files and whatever new metadata formats we support.