Using Gradle with custom Ivy repository
Asked Answered
D

1

7

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!

Droplet answered 2/4, 2014 at 18:41 Comment(5)
I think you need to use the maven pattern, then reconfigure it similar to the above.Seleta
Not sure what you mean? Where would I use the maven pattern? I can't change the existing ivy layout...Crossroad
Sorry I meant maven layout.Seleta
In other words, you'd use layout 'maven', { ... }. This should give Maven-style group separators.Seleta
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.11Crossroad
S
6

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

repositories {
    ivy {
        url ...
        layout 'pattern', {
            m2compatible = true
            ...
        }
    }
}
Seleta answered 3/4, 2014 at 9:8 Comment(2)
Should I still include the artifact and ivy patterns? If I do I see the following in the logging: [HTTP HEAD: svnserver/svn_public/trunk/ivyrepository/org.apache/…. So Gradle is still searching in a directory 'org.apache'. If I don't add those patterns it, I don't see any download attempt; I just get: "Could not find org.apache:commons-lang:2.4". Don't know whether it's related but the m2Compatible property seems to be deprecated ("Deprecated dynamic property: "m2Compatible")?Crossroad
Sorry it's m2compatible (with lower-case c). Yes, you should include the patterns. "Deprecated dynamic property" is usually the result of a spelling mistake. In Gradle 2.x, this will be an error rather than a warning.Seleta

© 2022 - 2024 — McMap. All rights reserved.