3

I've got an Ivy repository with multiple published artifacts, something like this:

/mygroup/mymodule/1.1.1/mymodule-1.1.1.jar
/mygroup/mymodule/1.1.1/mymodule-client-1.1.1.jar
/mygroup/mymodule/1.1.1/ivy-1.1.1.xml

If I put in the following gradle dependency line, it retrieves both jars. I want to only retrieve the mymodule-client.jar, but I can't figure out the incantation to make that work. Here's the line I have now. I've purposefully excluded transitive dependencies for other reasons.

compile ('mygroup:mymodule:1.1.11') {transitive=false}

Gradle docs seem to indicate there's a way to get just a specific artifact, but I can't get the incantation correct.

Here's the contents of the ivy file. Only the module/artifact names were changed and some standard dependency stuff removed for brevity.

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">

    <info organisation="mygroup" module="mymodule" revision="1.1.1" status="integration" publication="20120111091627"/>

    <publications>
        <artifact name="mymodule"/>
        <artifact name="mymodule-client"/>
    </publications>

    <dependencies> 
       ...          
    </dependencies>
</ivy-module>
Chris Kessel
  • 5,583
  • 4
  • 36
  • 55
  • It seems to me that your Maven repository is reporting that this artifact (`mymodule`) is a composite of multiple JARs + an XML file. Maybe the problem lies there, not on the Gradle side (your Gradle syntax seems correct). – ashes999 Dec 30 '13 at 17:13
  • It's actually artifactory, when I think imported an older Ivy repository once upon a time. If you look in the ivy-1.1.1.xml file, you can see it publishes both jars, both are elements in the . The gradle line works, it just pulls in both artifacts and I only want the "client" one. – Chris Kessel Dec 30 '13 at 17:22
  • 1
    Can you post the contents of `ivy-1.1.1.xml` please? – ashes999 Dec 30 '13 at 17:34
  • Do you have `mymodule-client` listed in `dependencies`? – ashes999 Dec 30 '13 at 17:44
  • No, the dependencies are a just couple other jars created in our company, like "myorg-common-utils" type of stuff, which have no other dependencies. – Chris Kessel Dec 30 '13 at 17:48

2 Answers2

2

The Ivy module descriptor doesn't assign the artifacts to different configurations, hence it's not possible to retrieve them independently. If all you want is to only put one of the two artifacts on the compile class path, something like the following should work:

configurations {
    mymodule
}

dependencies {
    mymodule 'mygroup:mymodule:1.1.1'
    compile configurations.mymodule.filter { it.name == 'mymodule-client-1.1.1.jar' } 
}
Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
2

Managed to find the appropriate line after a lot of trial and error:

compile ('mygroup:mymodule:1.1.1:client@jar')

I think it only works because the "client" is an extension of the module name (called a classifier apparently). If I'd had something named differently, I'm not sure how I'd have resolved it.

I found the example that gave me the clue here: http://scratchpad.pietschy.com/gradle/dependency_management.html

20.2.2.2. Artifact only notation An artifact only notation creates a module dependency which only downloads one artifact file. The notation for such a dependency follows the pattern: [group]:[artifact]:[version]@[extension] or [group]:[artifact]:[version]:[classifier]@[extension]. For example:

dependencies { compile "org.apache.ant:ant-junit:1.7.0@jar" }

Chris Kessel
  • 5,583
  • 4
  • 36
  • 55
  • I was having the same problem with an IVY repo that had the implementation jar, source jar, and javadoc jar artifacts all within the same module. Since the implementation jar didn't have the classifier attribute set I couldn't just that to differentiate it from the javadoc & source. Using the "@jar" notation worked great. – jenglert Jan 25 '14 at 00:06
  • 1
    FYI, by now the official docs for the "Artifact only notation" section is [here](http://www.gradle.org/docs/current/userguide/dependency_management.html#ssub:artifact_dependencies). – sschuberth Jul 23 '14 at 10:03