7
votes

I'm new to Gradle/Groovy so possibly I'm missing something obvious. Can you help?

We're using Ivy for dependency management. I'm trying out Gradle and want to integrate with our existing Ivy infrastructure. Normally this should be possible, but the layout of our Ivy is a bit idiosyncratic and well... I can't get it to work.

Take for example commons-lang-2.4.jar.

Typically, you'd fetch this file via ivy like so (cf. http://mvnrepository.com/artifact/commons-lang/commons-lang/2.4):

<dependency org="commons-lang" name="commons-lang" rev="2.4"/>

But we have to do it like so:

<dependency org="org.apache" name="commons-lang" rev="2.4" conf="compile"/>

That's because our Ivy is laid out taking into account the organization's url, e.g. like so:

<ivyrepository>/org/apache/commons-lang/2.4/commons-lang-2.4.jar

I have now tried to translate this to Gradle:

repositories {
    ivy {
        url 'http://svnserver/svn_public/trunk/ivyrepository'
        layout 'pattern', {
            artifact '[organisation]/[module]/[revision]/[artifact]-[revision].[ext]'
            ivy '[organisation]/[module]/[revision]/[module]-[revision].ivy'
        }
    }
}

dependencies {
    compile 'org.apache:commons-lang:2.4'
}

This is of course failing, as '[organisation]/[module]' translates to 'org.apache/commons-lang', and it should translate to org/apache/commons-lang!

So I tried this, naively thinking that replaceAll() would replace those dots with slashes:

repositories {
    ivy {
        url 'http://svnserver/svn_public/trunk/ivyrepository'
        layout 'pattern', {
            artifact '[organisation].replaceAll(\'.\',\'/\')/[module]/[revision]/[module]-[revision].jar'
            ivy '[organisation].replaceAll(\'.\',\'/\')/[module]/[revision]/[module]-[revision].ivy'
        }
    }
}

Alas, the function is not evaluated! Help!

1
I think you need to use the maven pattern, then reconfigure it similar to the above. - Peter Niederwieser
Not sure what you mean? Where would I use the maven pattern? I can't change the existing ivy layout... - David Bulté
Sorry I meant maven layout. - Peter Niederwieser
In other words, you'd use layout 'maven', { ... }. This should give Maven-style group separators. - Peter Niederwieser
Thx. But this gives me the following exception: "Could not find method artifact() for arguments [[organisation]/[module]/[revision]/[artifact]-[revision](-[classifier]).[ext]] on ...MavenRepositoryLayout_Decorated@5c2445". I'm using version 1.11 - David Bulté

1 Answers

6
votes

To get a Maven-style layout for the organisation part, use:

repositories {
    ivy {
        url ...
        layout 'pattern', {
            m2compatible = true
            ...
        }
    }
}