Search code examples
gradleivy

How are Ivy custom layouts interpreted by Gradle?


I have declared a custom ivy repository layout:

repositories {
    ivy {
        url "https://myurl.com/root/"
        layout 'pattern', {
             artifact "[organisation]/[name]-[version].[ext]"
        }
    }
}

and then I declare a dependency:

dependencies {
   compile 'mygroup:myartifact:0.1@zip'
}

but for some reason it doesn't work, Gradle doesn't find the dependency, and it seems to look in the wrong place: https://myurl.com/root/mygroup/[name]-[version].zip

I have also tried doing fancy things such as the following:

dependencies {
   compile module ('mygroup:myartifact:0.1@zip') {
      artifact {
         name = 'myartifact'
         ...
      }
   }
}

but it doesn't work either.

How to correctly define the layout pattern so that it be well interpreted by Gradle ?


Solution

  • When you specify a dependency with '<group>:<artifact>:<version>(@<ext>)', Gradle applies the following mapping to the pattern :

    • <group> replaces [organisation]
    • <artifact> replaces [module]
    • <version> replaces [revision]
    • <ext> replaces [ext]

    So in your case, your pattern should look like:

    artifact "[organisation]/[module]-[revision].[ext]"
    

    Credit to @RaGe for his answer