Ed Dunn
Ed Dunn

Reputation: 1172

gradle: downloading specific file from ivy repository

We use an internal ivy repository and are in the process from moving away from ant / ivy and tasking everything in gradle. I have my ivy repository set up in gradle as so:

repositories {
    ivy {
        url "${ivy_repository_url}"
        layout "pattern", {
            ivy "repository/[organisation]/[module]/[revision]/[artifact].[ext]"
            artifact "repository/[organisation]/[module]/[revision]/[artifact].[ext]"
            m2compatible = true
        }
        credentials {
            username "${ivy_repository_username}"
            password "${ivy_repository_password}"
        }
    }
}

and upon executing a task it resolves as expected, however, in some instances it pulls down everything in the repository if the naming convention doesn't match so I end up with a lot of extra stuff, javadocs.zip, sources.zip and everything else.

To get around this I want to download the specific jar files to a temp folder first and then compile them from local but I have no clue how to tell gradle to download a file that is named differently from the module name.

Example:

ivyFiles 'net.sourceforge.jtidy:jtidy:r938@jar'

downloads just jtidy-r938.jar from the net.sourceforge.jtidy repository but something like

ivyFiles 'com.gargoylesoftware:htmlunit:2.7@jar'

would pull htmlunit-2.7.jar but not the file htmlunit-core-js-2.7.jar.

If I omit the @jar it reverts to calling the ivy.xml file and I am left with all the junk + dependencies which I am trying to avoid. I have tried the following with no success

    ivyFiles ('com.gargoylesoftware:htmlunit:2.7'){
        artifact{
            name = 'htmlunit-core-js'
            type = 'jar'
        }
    }

There must be a way to do this.

Thank you

Upvotes: 1

Views: 1034

Answers (1)

Ed Dunn
Ed Dunn

Reputation: 1172

I figured it out. This is what I ended up doing

ivyFiles ('com.gargoylesoftware:htmlunit:2.7'){
    transitive = false
    artifact {
        name = 'htmlunit-core-js'
        extension = 'jar'
        type = 'jar'
    }
}

Now only the htmlunit-core-js-2.7.jar file was downloaded

Upvotes: 1

Related Questions